diff --git a/promql/engine.go b/promql/engine.go index 1cdac0828..7d27d586d 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -217,6 +217,9 @@ type ( ErrQueryTimeout string // ErrQueryCanceled is returned if a query was canceled during processing. ErrQueryCanceled string + // ErrStorage is returned if an error was encountered in the storage layer + // during query handling. + ErrStorage error ) func (e ErrQueryTimeout) Error() string { return fmt.Sprintf("query timed out in %s", string(e)) } diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 4f3e25f78..7cc588065 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -50,6 +50,7 @@ const ( errorCanceled = "canceled" errorExec = "execution" errorBadData = "bad_data" + errorInternal = "internal" ) var corsHeaders = map[string]string{ @@ -194,6 +195,8 @@ func (api *API) query(r *http.Request) (interface{}, *apiError) { return nil, &apiError{errorCanceled, res.Err} case promql.ErrQueryTimeout: return nil, &apiError{errorTimeout, res.Err} + case promql.ErrStorage: + return nil, &apiError{errorInternal, res.Err} } return nil, &apiError{errorExec, res.Err} } @@ -459,6 +462,8 @@ func respondError(w http.ResponseWriter, apiErr *apiError, data interface{}) { code = 422 case errorCanceled, errorTimeout: code = http.StatusServiceUnavailable + case errorInternal: + code = http.StatusInternalServerError default: code = http.StatusInternalServerError }