Include HTTP status code in Prometheus error responses

When Prometheus returns an HTTP error (4xx/5xx), the error message now
includes the status code and reason phrase. Previously, only the response
body was shown, which made it difficult to diagnose issues like HTTP 403
errors caused by missing authorization policies.

Fixes fluxcd/flagger#1434

Signed-off-by: rohansood10 <rohansood10@users.noreply.github.com>
This commit is contained in:
rohansood10
2026-02-19 03:11:46 -08:00
parent d4cc9bf616
commit 6a0096302f

View File

@@ -143,7 +143,7 @@ func (p *PrometheusProvider) RunQuery(query string) (float64, error) {
}
if 400 <= r.StatusCode {
return 0, fmt.Errorf("error response: %s", string(b))
return 0, fmt.Errorf("error response: Status %d %s: %s", r.StatusCode, http.StatusText(r.StatusCode), string(b))
}
var result prometheusResponse