vmselect: change HTTP response code for Prometheus querying API requests when parameters are missing or incorrect

This commit is contained in:
Hui Wang
2026-08-04 17:28:52 +08:00
parent a8759a539c
commit 545b977e7a
4 changed files with 62 additions and 50 deletions

View File

@@ -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)