Add detail about HTTP error messages

* resp.Status includes both the code and the textual description
* If Location is available (i.e. this is a redirect), show it
This commit is contained in:
Ohad Lutzky 2022-02-04 22:13:42 +00:00
parent 6304d91c26
commit e996f0b201

View File

@ -86,7 +86,10 @@ func (c *Client) DoRequest(endpoint string, target interface{}) error {
return err
}
if !(resp.StatusCode >= 200 && resp.StatusCode < 300) {
errMsg := fmt.Sprintf("An error has occurred during retrieving statistics HTTP statuscode %d", resp.StatusCode)
errMsg := fmt.Sprintf("An error has occurred during retrieving statistics HTTP status %s", resp.Status)
if location := resp.Header.Get("Location"); location != "" {
errMsg += " (Location: " + location + ")"
}
log.Fatal(errMsg)
return errors.New(errMsg)
}