From dfa83a4a3546bd8c7718952511037f074f6c365f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 3 Jul 2020 18:36:21 +0300 Subject: [PATCH] lib/promscrape: check for nil error before checking for the returned status code when scraping targets --- lib/promscrape/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 2a1524c82..34492b5a8 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -91,7 +91,7 @@ func (c *client) ReadData(dst []byte) ([]byte, error) { resp := fasthttp.AcquireResponse() err := doRequestWithPossibleRetry(c.hc, req, resp) statusCode := resp.StatusCode() - if statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound { + if err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) { // Allow a single redirect. // It is expected that the redirect is made on the same host. // Otherwise it won't work.