lib/promscrape: check for nil error before checking for the returned status code when scraping targets

This commit is contained in:
Aliaksandr Valialkin 2020-07-03 18:36:21 +03:00
parent d28fb0baf9
commit dfa83a4a35

View file

@ -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.