optimize: add more detail error message in serverErrorHandler (#2267)

pull/2273/head
kinggo 2022-12-11 02:28:39 +08:00 committed by GitHub
parent 2e3f73cb4d
commit a9ddef7a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

2
app.go
View File

@ -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 {

View File

@ -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()