Add promql.ErrStorage, which is interpreted by the API as a 500.

This commit is contained in:
Tom Wilkie 2017-04-04 17:22:51 +01:00
parent 5f3327f620
commit f0e8a5f37c
2 changed files with 8 additions and 0 deletions

View File

@ -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)) }

View File

@ -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
}