Skip to content

Commit

Permalink
Update client.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaying-peng committed Jun 12, 2024
1 parent 5deff57 commit 6825448
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bitcoin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 6825448

Please sign in to comment.