From 86f75be4073bfc93a30217fbac5f77ca0b45c5ba Mon Sep 17 00:00:00 2001 From: Friedrich Albert Kyuri Date: Sat, 12 Mar 2022 18:07:36 +0200 Subject: [PATCH] improve error handling on non-ok response Signed-off-by: Friedrich Albert Kyuri --- pkg/scalers/metrics_api_scaler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/scalers/metrics_api_scaler.go b/pkg/scalers/metrics_api_scaler.go index fd62a5bc773..80d9f16d715 100644 --- a/pkg/scalers/metrics_api_scaler.go +++ b/pkg/scalers/metrics_api_scaler.go @@ -210,13 +210,13 @@ func (s *metricsAPIScaler) getMetricValue(ctx context.Context) (*resource.Quanti if err != nil { return nil, err } + defer r.Body.Close() if r.StatusCode != http.StatusOK { - msg := fmt.Sprintf("api returned %d", r.StatusCode) + msg := fmt.Sprintf("%s: api returned %d", r.Request.URL.String(), r.StatusCode) return nil, errors.New(msg) } - defer r.Body.Close() b, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err