@cryptotaxi247 / kubo / commits / b6ace8dd4

response: handle late errors

This commit was moved from ipfs/go-ipfs-http-client@139e9e5ff1b52a92c169d28bf56ff58e36b49ca3

Łukasz Magiera committed Feb 18, 2019 at 17:12 UTC b6ace8dd401321b842c5f0054d9ed025fd19cd89
2 files changed +10 -5
client/httpapi/requestbuilder.go
+2 -2
@@ -103,11 +103,11 @@ func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error {
103 }
104
105 if res == nil {
106 - httpRes.Close()
106 + lateErr := httpRes.Close()
107 if httpRes.Error != nil {
108 return httpRes.Error
109 }
110 - return nil
110 + return lateErr
111 }
112
113 return httpRes.Decode(res)
client/httpapi/response.go
+8 -3
@@ -39,9 +39,14 @@ type Response struct {
39
40 func (r *Response) Close() error {
41 if r.Output != nil {
42 - // always drain output (response body)
43 - //ioutil.ReadAll(r.Output) // TODO: might not be a good idea in case there is a lot of data
44 - return r.Output.Close()
42 +
43 + // always drain output (response body) //TODO: make optional for things like cat
44 + _, err1 := io.Copy(ioutil.Discard, r.Output)
45 + err2 := r.Output.Close()
46 + if err1 != nil {
47 + return err1
48 + }
49 + return err2
50 }
51 return nil
52 }