Skip to content

Commit

Permalink
optimize: add more detail error message in serverErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou committed Dec 10, 2022
1 parent affa759 commit 985e0cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app.go
Expand Up @@ -1031,7 +1031,7 @@ func (app *App) serverErrorHandler(fctx *fasthttp.RequestCtx, err error) {
} else if strings.Contains(err.Error(), "timeout") {
err = ErrRequestTimeout
} else {
err = ErrBadRequest
err = NewError(StatusBadRequest, err.Error())
}

if catch := app.ErrorHandler(c, err); catch != nil {
Expand Down
10 changes: 10 additions & 0 deletions app_test.go
Expand Up @@ -245,6 +245,16 @@ func Test_App_ErrorHandler_RouteStack(t *testing.T) {
utils.AssertEqual(t, "1: USE error", string(body))
}

func Test_App_serverErrorHandler_Internal_Error(t *testing.T) {
app := New()
msg := "test err"
c := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(c)
app.serverErrorHandler(c.fasthttp, errors.New(msg))
utils.AssertEqual(t, string(c.fasthttp.Response.Body()), msg)
utils.AssertEqual(t, c.fasthttp.Response.StatusCode(), StatusBadRequest)
}

func Test_App_Nested_Params(t *testing.T) {
app := New()

Expand Down

0 comments on commit 985e0cd

Please sign in to comment.