Merge pull request #544 from kelgon/master

(fix #543)added response body to error when util.Post encounter 4xx response
This commit is contained in:
Chris Lu 2017-07-28 23:33:22 -07:00 committed by GitHub
commit 1129956f7f

View file

@ -48,10 +48,14 @@ func Post(url string, values url.Values) ([]byte, error) {
return nil, err return nil, err
} }
defer r.Body.Close() defer r.Body.Close()
if r.StatusCode >= 400 {
return nil, fmt.Errorf("%s: %s", url, r.Status)
}
b, err := ioutil.ReadAll(r.Body) b, err := ioutil.ReadAll(r.Body)
if r.StatusCode >= 400 {
if err != nil {
return nil, fmt.Errorf("%s: %d - %s", url, r.StatusCode, string(b))
} else {
return nil, fmt.Errorf("%s: %s", url, r.Status)
}
}
if err != nil { if err != nil {
return nil, err return nil, err
} }