func EllipticsErrorToStatus(err error) int { status := http.StatusBadRequest if de, ok := err.(*elliptics.DnetError); ok { err_code := elliptics.ErrorCode(de) switch syscall.Errno(-err_code) { case syscall.ENXIO: status = http.StatusServiceUnavailable case syscall.ETIMEDOUT: status = http.StatusServiceUnavailable case syscall.EIO: status = http.StatusServiceUnavailable case syscall.ENOENT: status = http.StatusNotFound case syscall.EILSEQ: status = http.StatusNotFound case syscall.EBADFD: status = http.StatusNotFound case syscall.EINVAL: status = http.StatusBadRequest } } return status }
func NewKeyErrorFromEllipticsError(ellerr error, url, message string) (err *KeyError) { err_code := elliptics.ErrorCode(ellerr) err_message := elliptics.ErrorData(ellerr) status := EllipticsErrorToStatus(ellerr) err = NewKeyError(url, status, fmt.Sprintf("%s: elliptics-code: %d, elliptics-message: %s", message, err_code, err_message)) return }