diff --git a/client.go b/client.go
index 1e228a09..ed8595e0 100644
--- a/client.go
+++ b/client.go
@@ -289,9 +289,6 @@ func (c *Client) handleErrorResp(resp *http.Response) error {
if err != nil {
return fmt.Errorf("error, reading response body: %w", err)
}
- if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
- return fmt.Errorf("error, status code: %d, status: %s, body: %s", resp.StatusCode, resp.Status, body)
- }
var errRes ErrorResponse
err = json.Unmarshal(body, &errRes)
if err != nil || errRes.Error == nil {
diff --git a/client_test.go b/client_test.go
index 18da787a..354a6b3f 100644
--- a/client_test.go
+++ b/client_test.go
@@ -194,26 +194,31 @@ func TestHandleErrorResp(t *testing.T) {
{
"error":{}
}`)),
- expected: "error, status code: 503, status: , message: ",
+ expected: `error, status code: 503, status: , message: , body:
+ {
+ "error":{}
+ }`,
},
{
name: "413 Request Entity Too Large",
httpCode: http.StatusRequestEntityTooLarge,
contentType: "text/html",
- body: bytes.NewReader([]byte(`
-
413 Request Entity Too Large
-
-413 Request Entity Too Large
-
nginx
-
-`)),
- expected: `error, status code: 413, status: , body:
-413 Request Entity Too Large
-
-413 Request Entity Too Large
-
nginx
-
-`,
+ body: bytes.NewReader([]byte(`
+
+ 413 Request Entity Too Large
+
+ 413 Request Entity Too Large
+
nginx
+
+ `)),
+ expected: `error, status code: 413, status: , message: invalid character '<' looking for beginning of value, body:
+
+ 413 Request Entity Too Large
+
+ 413 Request Entity Too Large
+
nginx
+
+ `,
},
{
name: "errorReader",
diff --git a/error.go b/error.go
index fc9e7cdb..8a74bd52 100644
--- a/error.go
+++ b/error.go
@@ -104,7 +104,10 @@ func (e *APIError) UnmarshalJSON(data []byte) (err error) {
}
func (e *RequestError) Error() string {
- return fmt.Sprintf("error, status code: %d, status: %s, message: %s", e.HTTPStatusCode, e.HTTPStatus, e.Err)
+ return fmt.Sprintf(
+ "error, status code: %d, status: %s, message: %s, body: %s",
+ e.HTTPStatusCode, e.HTTPStatus, e.Err, e.Body,
+ )
}
func (e *RequestError) Unwrap() error {