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() resp := fasthttp.AcquireResponse()
err := doRequestWithPossibleRetry(c.hc, req, resp) err := doRequestWithPossibleRetry(c.hc, req, resp)
statusCode := resp.StatusCode() statusCode := resp.StatusCode()
if statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound { if err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) {
// Allow a single redirect. // Allow a single redirect.
// It is expected that the redirect is made on the same host. // It is expected that the redirect is made on the same host.
// Otherwise it won't work. // Otherwise it won't work.