Close resp.Body before returning error

This commit is contained in:
Jordan Liggitt
2015-07-10 11:08:54 -04:00
parent fbc85e9838
commit 39a5e1b929
2 changed files with 4 additions and 0 deletions

View File

@@ -614,6 +614,9 @@ func (r *Request) Stream() (io.ReadCloser, error) {
return resp.Body, nil
default:
// ensure we close the body before returning the error
defer resp.Body.Close()
// we have a decent shot at taking the object returned, parsing it as a status object and returning a more normal error
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {