mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
Merge pull request #4866 from gouthamve/api-compat
web(api): Make query and range api errors match
This commit is contained in:
commit
d4b348a7b1
|
@ -284,15 +284,7 @@ func (api *API) query(r *http.Request) (interface{}, *apiError, func()) {
|
|||
|
||||
res := qry.Exec(ctx)
|
||||
if res.Err != nil {
|
||||
switch res.Err.(type) {
|
||||
case promql.ErrQueryCanceled:
|
||||
return nil, &apiError{errorCanceled, res.Err}, qry.Close
|
||||
case promql.ErrQueryTimeout:
|
||||
return nil, &apiError{errorTimeout, res.Err}, qry.Close
|
||||
case promql.ErrStorage:
|
||||
return nil, &apiError{errorInternal, res.Err}, qry.Close
|
||||
}
|
||||
return nil, &apiError{errorExec, res.Err}, qry.Close
|
||||
return nil, returnAPIError(res.Err), qry.Close
|
||||
}
|
||||
|
||||
// Optional stats field in response if parameter "stats" is not empty.
|
||||
|
@ -358,13 +350,7 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError, func()) {
|
|||
|
||||
res := qry.Exec(ctx)
|
||||
if res.Err != nil {
|
||||
switch res.Err.(type) {
|
||||
case promql.ErrQueryCanceled:
|
||||
return nil, &apiError{errorCanceled, res.Err}, qry.Close
|
||||
case promql.ErrQueryTimeout:
|
||||
return nil, &apiError{errorTimeout, res.Err}, qry.Close
|
||||
}
|
||||
return nil, &apiError{errorExec, res.Err}, qry.Close
|
||||
return nil, returnAPIError(res.Err), qry.Close
|
||||
}
|
||||
|
||||
// Optional stats field in response if parameter "stats" is not empty.
|
||||
|
@ -380,6 +366,23 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError, func()) {
|
|||
}, nil, qry.Close
|
||||
}
|
||||
|
||||
func returnAPIError(err error) *apiError {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch err.(type) {
|
||||
case promql.ErrQueryCanceled:
|
||||
return &apiError{errorCanceled, err}
|
||||
case promql.ErrQueryTimeout:
|
||||
return &apiError{errorTimeout, err}
|
||||
case promql.ErrStorage:
|
||||
return &apiError{errorInternal, err}
|
||||
}
|
||||
|
||||
return &apiError{errorExec, err}
|
||||
}
|
||||
|
||||
func (api *API) labelValues(r *http.Request) (interface{}, *apiError, func()) {
|
||||
ctx := r.Context()
|
||||
name := route.Param(ctx, "name")
|
||||
|
|
Loading…
Reference in a new issue