diff --git a/bunq/client.go b/bunq/client.go index 5dc38b9..792babe 100644 --- a/bunq/client.go +++ b/bunq/client.go @@ -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)