Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 204 no content handling #654

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func responseLogger(c *Client, res *Response) error {

func parseResponseBody(c *Client, res *Response) (err error) {
if res.StatusCode() == http.StatusNoContent {
res.Request.Error = nil
return
}
// Handles only JSON or XML content type
Expand Down
4 changes: 2 additions & 2 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *Response) Cookies() []*http.Cookie {

// String method returns the body of the server response as String.
func (r *Response) String() string {
if r.body == nil {
if len(r.body) == 0 {
jeevatkm marked this conversation as resolved.
Show resolved Hide resolved
return ""
}
return strings.TrimSpace(string(r.body))
Expand Down Expand Up @@ -156,7 +156,7 @@ func (r *Response) setReceivedAt() {
}

func (r *Response) fmtBodyString(sl int64) string {
if r.body != nil {
if len(r.body) > 0 {
jeevatkm marked this conversation as resolved.
Show resolved Hide resolved
if int64(len(r.body)) > sl {
return fmt.Sprintf("***** RESPONSE TOO LARGE (size - %d) *****", len(r.body))
}
Expand Down