Skip to content

Commit

Permalink
[fix] don't panic on invalid response without error
Browse files Browse the repository at this point in the history
  • Loading branch information
gjongenelen authored Nov 1, 2021
1 parent c05695c commit 8d9e7c8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions bunq/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,20 @@ func (c *Client) do(r *http.Request) (*http.Response, error) {

errResponse := createErrorResponse(res)

return nil, fmt.Errorf(
"bunq: http request failed with status %d and description %q and response header: %q",
res.StatusCode,
errResponse.Error[0].ErrorDescription,
res.Header.Get("X-Bunq-Client-Response-Id"),
)
if len(errResponse.Error) == 0 {
return nil, fmt.Errorf(
"bunq: http request failed with status %d and response header: %q",
res.StatusCode,
res.Header.Get("X-Bunq-Client-Response-Id"),
)
} else {
return nil, fmt.Errorf(
"bunq: http request failed with status %d and description %q and response header: %q",
res.StatusCode,
errResponse.Error[0].ErrorDescription,
res.Header.Get("X-Bunq-Client-Response-Id"),
)
}
}

err = c.verifyResponse(r, res)
Expand Down

0 comments on commit 8d9e7c8

Please sign in to comment.