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

Method ErrorHandler

app.go:1550–1585  ·  app.go::App.ErrorHandler

ErrorHandler is the application's method in charge of finding the appropriate handler for the given request. It searches any mounted sub fibers by their prefixes and if it finds a match, it uses that error handler. Otherwise, it uses the configured error handler for the app, which if not set is the

(ctx Ctx, err error)

Source from the content-addressed store, hash-verified

1548// error handler. Otherwise, it uses the configured error handler for
1549// the app, which if not set is the DefaultErrorHandler.
1550func (app *App) ErrorHandler(ctx Ctx, err error) error {
1551 // Fast path: no mounted sub-apps, so no prefix lookup is needed
1552 if len(app.mountFields.appListKeys) == 0 {
1553 return app.config.ErrorHandler(ctx, err)
1554 }
1555
1556 var (
1557 mountedErrHandler ErrorHandler
1558 mountedPrefixParts int
1559 )
1560
1561 normalizedPath := utils.AddTrailingSlashString(ctx.Path())
1562
1563 for _, prefix := range app.mountFields.appListKeys {
1564 subApp := app.mountFields.appList[prefix]
1565 normalizedPrefix := utils.AddTrailingSlashString(prefix)
1566
1567 if prefix != "" && strings.HasPrefix(normalizedPath, normalizedPrefix) {
1568 // Count slashes instead of splitting - more efficient
1569 parts := strings.Count(prefix, "/") + 1
1570 if mountedPrefixParts <= parts {
1571 if subApp.configured.ErrorHandler != nil {
1572 mountedErrHandler = subApp.config.ErrorHandler
1573 }
1574
1575 mountedPrefixParts = parts
1576 }
1577 }
1578 }
1579
1580 if mountedErrHandler != nil {
1581 return mountedErrHandler(ctx, err)
1582 }
1583
1584 return app.config.ErrorHandler(ctx, err)
1585}
1586
1587// serverErrorHandler is a wrapper around the application's error handler method
1588// user for the fasthttp server configuration. It maps a set of fasthttp errors to fiber

Callers 10

serverErrorHandlerMethod · 0.95
defaultRequestHandlerMethod · 0.80
customRequestHandlerMethod · 0.80
NewFunction · 0.80
DeleteTokenMethod · 0.80
NewFunction · 0.80
handlerFuncFunction · 0.80
saveSessionMethod · 0.80
NewFunction · 0.80

Calls 1

PathMethod · 0.65