mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-08-08 08:47:41 +03:00
vmselect: change HTTP response code for Prometheus querying API requests when parameters are missing or incorrect
This commit is contained in:
@@ -5,9 +5,18 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// SendPrometheusError sends err to w in Prometheus querying API response format.
|
||||
//
|
||||
// See https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview for more details
|
||||
// InvalidParamError sets HTTP status code to 400 Bad Request for Prometheus querying APIs when parameters are missing or incorrect,
|
||||
// see https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview.
|
||||
func InvalidParamError(err error) *ErrorWithStatusCode {
|
||||
return &ErrorWithStatusCode{
|
||||
Err: err,
|
||||
StatusCode: http.StatusBadRequest,
|
||||
}
|
||||
}
|
||||
|
||||
// SendPrometheusError sends err to w in Prometheus querying API response format,
|
||||
// and sets HTTP status code to 422 Unprocessable Entity when code is not set,
|
||||
// see https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview for more details.
|
||||
func SendPrometheusError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
errStr := err.Error()
|
||||
logHTTPError(r, errStr)
|
||||
|
||||
Reference in New Issue
Block a user