Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
response: handle late errors
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 18, 2019
1 parent 5c96c29 commit 139e9e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions requestbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error {
}

if res == nil {
httpRes.Close()
lateErr := httpRes.Close()
if httpRes.Error != nil {
return httpRes.Error
}
return nil
return lateErr
}

return httpRes.Decode(res)
Expand Down
11 changes: 8 additions & 3 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ type Response struct {

func (r *Response) Close() error {
if r.Output != nil {
// always drain output (response body)
//ioutil.ReadAll(r.Output) // TODO: might not be a good idea in case there is a lot of data
return r.Output.Close()

// always drain output (response body) //TODO: make optional for things like cat
_, err1 := io.Copy(ioutil.Discard, r.Output)
err2 := r.Output.Close()
if err1 != nil {
return err1
}
return err2
}
return nil
}
Expand Down

0 comments on commit 139e9e5

Please sign in to comment.