Skip to content

Commit

Permalink
improve response unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Jun 1, 2022
1 parent 2e4b6f6 commit 029862c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,25 @@ func parseResponseBody(c *Client, r *Response) (err error) {
return
}
// Handles only JSON or XML content type
if r.Request.Result != nil && r.IsSuccess() {
unmarshalBody(c, r, r.Request.Result)
if r.Request.Result != nil {
if r.IsSuccess() {
err = unmarshalBody(c, r, r.Request.Result)
if err != nil {
r.Request.Result = nil
}
} else {
r.Request.Result = nil
}
}
if r.Request.Error != nil && r.IsError() {
unmarshalBody(c, r, r.Request.Error)
if r.Request.Error != nil {
if r.IsError() {
err = unmarshalBody(c, r, r.Request.Error)
if err != nil {
r.Request.Error = nil
}
} else {
r.Request.Error = nil
}
}
return
}
Expand Down

0 comments on commit 029862c

Please sign in to comment.