Improve slack error handling

Signed-off-by: Diogo Nicoleti <diogo.nicoleti@gmail.com>
This commit is contained in:
Diogo Nicoleti 2019-05-30 14:45:32 -03:00
parent 7f4e70e0f4
commit 9ca88e3ebf
No known key found for this signature in database
GPG Key ID: F514B59A23EF79BB

View File

@ -596,19 +596,17 @@ func (n *Slack) retry(resp *http.Response) (bool, error) {
// https://api.slack.com/changelog/2016-05-17-changes-to-errors-for-incoming-webhooks
statusCode := resp.StatusCode
if statusCode/100 == 4 && resp.Body != nil {
var err error
if statusCode/100 != 2 {
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, fmt.Errorf("unexpected status code %v: problem reading response: %v", statusCode, err)
err = fmt.Errorf("unexpected status code %v", statusCode)
} else {
err = fmt.Errorf("unexpected status code %v: %s", statusCode, string(bs))
}
return false, fmt.Errorf("unexpected status code %v: %v", statusCode, string(bs))
}
if statusCode/100 != 2 {
return (statusCode/100 == 5), fmt.Errorf("unexpected status code %v", statusCode)
}
return false, nil
return (statusCode/100 == 5), err
}
// Hipchat implements a Notifier for Hipchat notifications.