Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 09fc3a2

Browse files
committed
handle late errors when ignoring the response value
1 parent a49a9cb commit 09fc3a2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: request.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ type Response struct {
6868
func (r *Response) Close() error {
6969
if r.Output != nil {
7070
// always drain output (response body)
71-
ioutil.ReadAll(r.Output)
72-
return r.Output.Close()
71+
_, err1 := io.Copy(ioutil.Discard, r.Output)
72+
err2 := r.Output.Close()
73+
if err1 != nil {
74+
return err1
75+
}
76+
if err2 != nil {
77+
return err2
78+
}
7379
}
7480
return nil
7581
}

Diff for: requestbuilder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error {
8989
}
9090

9191
if res == nil {
92-
httpRes.Close()
92+
lateErr := httpRes.Close()
9393
if httpRes.Error != nil {
9494
return httpRes.Error
9595
}
96-
return nil
96+
return lateErr
9797
}
9898

9999
return httpRes.Decode(res)

0 commit comments

Comments
 (0)