Skip to content

Commit

Permalink
fix: improve the code
Browse files Browse the repository at this point in the history
  • Loading branch information
mnavarrocarter committed Aug 18, 2022
1 parent ae2f989 commit 309a859
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ func reflectFunc(fn any) *reflectedFn {
case 1:
if t.Out(0).Implements(errorType) {
rFn.outFn = func(out []reflect.Value) (interface{}, error) {
if err, ok := out[0].Interface().(error); ok {
return nil, err
}
err, _ := out[0].Interface().(error)

return nil, nil
return nil, err
}
} else {
rFn.outFn = func(out []reflect.Value) (interface{}, error) {
Expand Down
13 changes: 13 additions & 0 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ func TestHandler(t *testing.T) {
expectedResponse: []byte(""),
expectedStatus: http.StatusNoContent,
},
{
name: "double nil error response",
req: func() *http.Request {
return httptest.NewRequest(http.MethodGet, "https://example.com", mustOpen(t, "valid.json"))
}(),
handler: func() (map[string]interface{}, error) {
return map[string]interface{}{
"msg": "hello",
}, nil
},
expectedResponse: []byte(`{"msg":"hello"}` + "\n"),
expectedStatus: http.StatusOK,
},
{
name: "panic response",
req: func() *http.Request {
Expand Down

0 comments on commit 309a859

Please sign in to comment.