Skip to content

Commit

Permalink
Merge pull request prometheus#2572 from weaveworks/2571-propagate-api…
Browse files Browse the repository at this point in the history
…-error

Add promql.ErrStorage, which the API propagates as a 500.
  • Loading branch information
juliusv authored Apr 6, 2017
2 parents fdd2bc2 + f0e8a5f commit beeb0b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }
Expand Down
5 changes: 5 additions & 0 deletions web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
errorCanceled = "canceled"
errorExec = "execution"
errorBadData = "bad_data"
errorInternal = "internal"
)

var corsHeaders = map[string]string{
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit beeb0b5

Please sign in to comment.