mirror of https://github.com/gofiber/fiber.git
optimize: add more detail error message in serverErrorHandler (#2267)
parent
2e3f73cb4d
commit
a9ddef7a20
2
app.go
2
app.go
|
@ -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 {
|
||||
|
|
10
app_test.go
10
app_test.go
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue