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

Function Test_Integration_Domain_ErrorHandling

app_integration_test.go:981–1006  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

979}
980
981func Test_Integration_Domain_ErrorHandling(t *testing.T) {
982 t.Parallel()
983
984 app := fiber.New(fiber.Config{
985 ErrorHandler: func(c fiber.Ctx, err error) error {
986 c.Set("X-Error-Handled", "true")
987 return c.Status(fiber.StatusInternalServerError).SendString("error: " + err.Error())
988 },
989 })
990 app.Use(helmet.New())
991
992 app.Domain("api.example.com").Get("/error", func(_ fiber.Ctx) error {
993 return fiber.NewError(fiber.StatusInternalServerError, "domain error")
994 })
995
996 req := httptest.NewRequest(http.MethodGet, "/error", http.NoBody)
997 req.Host = "api.example.com"
998 resp, err := app.Test(req)
999 require.NoError(t, err)
1000 require.Equal(t, fiber.StatusInternalServerError, resp.StatusCode)
1001 require.Equal(t, "true", resp.Header.Get("X-Error-Handled"))
1002 require.Equal(t, "nosniff", resp.Header.Get(fiber.HeaderXContentTypeOptions))
1003 body, err := io.ReadAll(resp.Body)
1004 require.NoError(t, err)
1005 require.Contains(t, string(body), "domain error")
1006}
1007
1008func Test_Integration_Domain_WithLimiter(t *testing.T) {
1009 t.Parallel()

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
TestMethod · 0.80
ContainsMethod · 0.80
NewMethod · 0.65
SetMethod · 0.65
SendStringMethod · 0.65
StatusMethod · 0.65
ErrorMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
DomainMethod · 0.65

Tested by

no test coverage detected