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)
| 11 | // |
| 12 | // See https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview for more details |
| 13 | func 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. |
| 32 | type UserReadableError struct { |
no test coverage detected
searching dependent graphs…