Browse Source

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

Add promql.ErrStorage, which the API propagates as a 500.
pull/2593/head
Julius Volz 8 years ago committed by GitHub
parent
commit
beeb0b55c0
  1. 3
      promql/engine.go
  2. 5
      web/api/v1/api.go

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

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

Loading…
Cancel
Save