Skip to content

Commit ae2f989

Browse files
fix: nil error response
1 parent fd89c93 commit ae2f989

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

function.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ 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-
return nil, out[0].Interface().(error)
37+
if err, ok := out[0].Interface().(error); ok {
38+
return nil, err
39+
}
40+
41+
return nil, nil
3842
}
3943
} else {
4044
rFn.outFn = func(out []reflect.Value) (interface{}, error) {

handler_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ func TestHandler(t *testing.T) {
134134
expectedResponse: []byte(`{"status":500,"details":"there was an error"}` + "\n"),
135135
expectedStatus: http.StatusInternalServerError,
136136
},
137+
{
138+
name: "nil error response",
139+
req: func() *http.Request {
140+
return httptest.NewRequest(http.MethodGet, "https://example.com", mustOpen(t, "valid.json"))
141+
}(),
142+
handler: func() error {
143+
return nil
144+
},
145+
expectedResponse: []byte(""),
146+
expectedStatus: http.StatusNoContent,
147+
},
137148
{
138149
name: "panic response",
139150
req: func() *http.Request {

0 commit comments

Comments
 (0)