Skip to content

Commit

Permalink
added response body in RequestError.Error() and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSawant18588 committed Oct 20, 2024
1 parent 22cf414 commit 71c217e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,29 @@ 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(`<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>`)),
expected: `error, status code: 413, status: , message: invalid character '<' looking for beginning of value`,
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>`)),
expected: `error, status code: 413, status: , message: invalid character '<' looking for beginning of value, body: <html>

Check failure on line 213 in client_test.go

View workflow job for this annotation

GitHub Actions / Sanity check

the line is 124 characters long, which exceeds the maximum of 120 characters. (lll)
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>`,
},
{
name: "errorReader",
Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ 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)

Check failure on line 107 in error.go

View workflow job for this annotation

GitHub Actions / Sanity check

the line is 127 characters long, which exceeds the maximum of 120 characters. (lll)
}

func (e *RequestError) Unwrap() error {
Expand Down

0 comments on commit 71c217e

Please sign in to comment.