diff --git a/client.go b/client.go index 9da189f6..87a88da2 100644 --- a/client.go +++ b/client.go @@ -1244,10 +1244,10 @@ func (c *Client) execute(req *Request) (*Response, error) { if err != nil || req.notParseResponse || c.notParseResponse { response.setReceivedAt() - logErr := responseLogger(c, response) - if logErr != nil { + if logErr := responseLogger(c, response); logErr != nil { return response, wrapErrors(logErr, err) - } else if err != nil { + } + if err != nil { return response, err } return response, nil diff --git a/util_test.go b/util_test.go index 6c030fd7..4d0a888d 100644 --- a/util_test.go +++ b/util_test.go @@ -6,6 +6,7 @@ package resty import ( "bytes" + "errors" "mime/multipart" "testing" ) @@ -89,3 +90,18 @@ func TestWriteMultipartFormFileReaderError(t *testing.T) { assertNotNil(t, err) assertEqual(t, "read error", err.Error()) } + +func TestRestyErrorFuncs(t *testing.T) { + ne1 := errors.New("new error 1") + nie1 := errors.New("inner error 1") + + e := wrapErrors(ne1, nie1) + assertEqual(t, "new error 1", e.Error()) + assertEqual(t, "inner error 1", errors.Unwrap(e).Error()) + + e = wrapErrors(ne1, nil) + assertEqual(t, "new error 1", e.Error()) + + e = wrapErrors(nil, nie1) + assertEqual(t, "inner error 1", e.Error()) +}