Skip to content

Commit

Permalink
Include response body in status error (#1) (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelb-gk authored Jul 20, 2024
1 parent 20b70ec commit feec0d0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ var (
// ErrStatusCode can be returned in case request to server resulted in wrong status code.
type ErrStatusCode struct {
Code int
Body []byte
}

func (e ErrStatusCode) Error() string {
return fmt.Sprintf("wrong status code: %d", e.Code)
return fmt.Sprintf("wrong status code: %d, body: %s", e.Code, string(e.Body))
}

// Config of client.
Expand Down Expand Up @@ -407,7 +408,8 @@ func (c *Client) send(ctx context.Context, commands []Command) ([]Reply, error)
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return nil, ErrStatusCode{resp.StatusCode}
respBody, _ := io.ReadAll(resp.Body)
return nil, ErrStatusCode{resp.StatusCode, respBody}
}

var replies []Reply
Expand Down

0 comments on commit feec0d0

Please sign in to comment.