Skip to content

Commit

Permalink
feat: add nil check to SetResult (#503) (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrop committed Mar 6, 2023
1 parent dc65180 commit 840c825
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ func (r *Request) SetBody(body interface{}) *Request {
// Accessing a result value from response instance.
// response.Result().(*AuthToken)
func (r *Request) SetResult(res interface{}) *Request {
r.Result = getPointer(res)
if res != nil {
r.Result = getPointer(res)
}
return r
}

Expand Down
10 changes: 10 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1891,3 +1891,13 @@ func TestPostBodyError(t *testing.T) {
assertEqual(t, "read error", err.Error())
assertNil(t, resp)
}

func TestSetResultMustNotPanicOnNil(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Errorf("must not panic")
}
}()
dc().R().SetResult(nil)
}

0 comments on commit 840c825

Please sign in to comment.