MCPcopy
hub / github.com/gofiber/fiber / Test_App_ErrorHandler_Custom

Function Test_App_ErrorHandler_Custom

app_test.go:581–600  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

579}
580
581func Test_App_ErrorHandler_Custom(t *testing.T) {
582 t.Parallel()
583 app := New(Config{
584 ErrorHandler: func(c Ctx, _ error) error {
585 return c.Status(200).SendString("hi, i'm a custom error")
586 },
587 })
588
589 app.Get("/", func(_ Ctx) error {
590 return errors.New("hi, i'm an error")
591 })
592
593 resp, err := app.Test(httptest.NewRequest(MethodGet, "/", http.NoBody))
594 require.NoError(t, err, "app.Test(req)")
595 require.Equal(t, 200, resp.StatusCode, "Status code")
596
597 body, err := io.ReadAll(resp.Body)
598 require.NoError(t, err)
599 require.Equal(t, "hi, i'm a custom error", string(body))
600}
601
602func Test_App_ErrorHandler_HandlerStack(t *testing.T) {
603 t.Parallel()

Callers

nothing calls this directly

Calls 6

TestMethod · 0.80
NewFunction · 0.70
SendStringMethod · 0.65
StatusMethod · 0.65
GetMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected