Skip to content

Commit 309a859

Browse files
fix: improve the code
1 parent ae2f989 commit 309a859

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

function.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ func reflectFunc(fn any) *reflectedFn {
3434
case 1:
3535
if t.Out(0).Implements(errorType) {
3636
rFn.outFn = func(out []reflect.Value) (interface{}, error) {
37-
if err, ok := out[0].Interface().(error); ok {
38-
return nil, err
39-
}
37+
err, _ := out[0].Interface().(error)
4038

41-
return nil, nil
39+
return nil, err
4240
}
4341
} else {
4442
rFn.outFn = func(out []reflect.Value) (interface{}, error) {

handler_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ func TestHandler(t *testing.T) {
145145
expectedResponse: []byte(""),
146146
expectedStatus: http.StatusNoContent,
147147
},
148+
{
149+
name: "double nil error response",
150+
req: func() *http.Request {
151+
return httptest.NewRequest(http.MethodGet, "https://example.com", mustOpen(t, "valid.json"))
152+
}(),
153+
handler: func() (map[string]interface{}, error) {
154+
return map[string]interface{}{
155+
"msg": "hello",
156+
}, nil
157+
},
158+
expectedResponse: []byte(`{"msg":"hello"}` + "\n"),
159+
expectedStatus: http.StatusOK,
160+
},
148161
{
149162
name: "panic response",
150163
req: func() *http.Request {

0 commit comments

Comments
 (0)