Merge pull request #2572 from weaveworks/2571-propagate-api-error

Add promql.ErrStorage, which the API propagates as a 500.
This commit is contained in:
Julius Volz 2017-04-06 16:36:20 +02:00 committed by GitHub
commit beeb0b55c0
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
}