MCPcopy Create free account
hub / github.com/VictoriaMetrics/VictoriaLogs / SendPrometheusError

Function SendPrometheusError

lib/httpserver/prometheus.go:13–29  ·  view source on GitHub ↗

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

(w http.ResponseWriter, r *http.Request, err error)

Source from the content-addressed store, hash-verified

11//
12// See https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview for more details
13func SendPrometheusError(w http.ResponseWriter, r *http.Request, err error) {
14 logger.WarnfSkipframes(1, "error in %q: %s", GetRequestURI(r), err)
15
16 w.Header().Set("Content-Type", "application/json")
17 statusCode := http.StatusUnprocessableEntity
18 var esc *ErrorWithStatusCode
19 if errors.As(err, &esc) {
20 statusCode = esc.StatusCode
21 }
22 w.WriteHeader(statusCode)
23
24 var ure *UserReadableError
25 if errors.As(err, &ure) {
26 err = ure
27 }
28 WritePrometheusErrorResponse(w, statusCode, err)
29}
30
31// UserReadableError is a type of error which supposed to be returned to the user without additional context.
32type UserReadableError struct {

Callers 4

RequestHandlerFunction · 0.92
ProcessStatsQueryRequestFunction · 0.92

Calls 6

WarnfSkipframesFunction · 0.92
GetRequestURIFunction · 0.85
HeaderMethod · 0.80
SetMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…