From 6825448fda33c4ec0d66e5947a9b724be104511d Mon Sep 17 00:00:00 2001 From: Xiaying Peng Date: Wed, 12 Jun 2024 11:02:23 -0700 Subject: [PATCH] Update client.go --- bitcoin/client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bitcoin/client.go b/bitcoin/client.go index c6f0d9e4..3966eb91 100644 --- a/bitcoin/client.go +++ b/bitcoin/client.go @@ -20,7 +20,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "strconv" @@ -835,11 +835,15 @@ func (b *Client) post( if err != nil { return fmt.Errorf("%w: error posting to rpc-api", err) } - defer res.Body.Close() - + defer func() { + if cerr := res.Body.Close(); cerr != nil { + // Log or handle the error + fmt.Printf("Failed to close response body: %v", cerr) + } + }() // We expect JSON-RPC responses to return `200 OK` statuses if res.StatusCode != http.StatusOK { - val, _ := ioutil.ReadAll(res.Body) + val, _ := io.ReadAll(res.Body) return fmt.Errorf("invalid response: %s %s", res.Status, string(val)) }