Skip to content

Commit

Permalink
fix: do not use errors.Join, just use custom error approach
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 21, 2024
1 parent 19530bc commit 33f6035
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 1248 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L1248

Added line #L1248 was not covered by tests
} else if err != nil {
}
if err != nil {
return response, err
}
return response, nil
Expand Down
16 changes: 16 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package resty

import (
"bytes"
"errors"
"mime/multipart"
"testing"
)
Expand Down Expand Up @@ -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())
}

0 comments on commit 33f6035

Please sign in to comment.