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

Function Test_App_ErrorHandler_RouteStack

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

Source from the content-addressed store, hash-verified

630}
631
632func Test_App_ErrorHandler_RouteStack(t *testing.T) {
633 t.Parallel()
634 app := New(Config{
635 ErrorHandler: func(c Ctx, err error) error {
636 require.Equal(t, "1: USE error", err.Error())
637 return DefaultErrorHandler(c, err)
638 },
639 })
640 app.Use("/", func(c Ctx) error {
641 err := c.Next()
642 require.Equal(t, "0: GET error", err.Error())
643 return errors.New("1: USE error") // [2] call ErrorHandler
644 })
645 app.Get("/test", func(_ Ctx) error {
646 return errors.New("0: GET error") // [1] return to USE
647 })
648
649 resp, err := app.Test(httptest.NewRequest(MethodGet, "/test", http.NoBody))
650 require.NoError(t, err, "app.Test(req)")
651 require.Equal(t, 500, resp.StatusCode, "Status code")
652
653 body, err := io.ReadAll(resp.Body)
654 require.NoError(t, err)
655 require.Equal(t, "1: USE error", string(body))
656}
657
658func Test_DefaultErrorHandler_TypedNilFiberError(t *testing.T) {
659 t.Parallel()

Callers

nothing calls this directly

Calls 8

TestMethod · 0.80
NewFunction · 0.70
DefaultErrorHandlerFunction · 0.70
ErrorMethod · 0.65
UseMethod · 0.65
NextMethod · 0.65
NewMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…