mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-06 08:47:52 +08:00
response: handle late errors
This commit was moved from ipfs/go-ipfs-http-client@139e9e5ff1
This commit is contained in:
parent
7229dbbf73
commit
b6ace8dd40
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user