Documentation
¶
Overview ¶
Package filter is the last line of the request pipeline: it turns anything that escaped a handler into a response.
Install ErrorHandler as Fiber's Config.ErrorHandler and no code path can return a bare Go error to a client.
What it guarantees, which hand-written error handling does not:
- Every failure is logged ONCE, with its internal cause, under the request's trace id — including the ones a handler returned without logging.
- No unclassified error's text reaches a client. An error that is not an *errs.Error is by definition one nobody checked for leaks, so it becomes a generic 500 and the original goes to the log.
- A 404 for an unrouted path looks like every other response, so a client's error parsing does not have to special-case the framework's own replies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
ErrorHandler returns a handler for fiber.Config.ErrorHandler.
app := fiber.New(fiber.Config{ErrorHandler: filter.ErrorHandler(filter.Options{})})
func NotFoundHandler ¶
NotFoundHandler is the terminal handler for unmatched routes. Register it LAST, after every module: `app.Use(filter.NotFoundHandler())`.
Types ¶
type Filter ¶
type Filter interface {
Name() string
Catch(c fiber.Ctx, err error) (handled bool, writeErr error)
}
Filter handles errors of a shape it recognises.
Catch returns handled=false to pass the error to the next filter. The chain always ends in the built-in behaviour, so a filter never has to handle everything.
type Options ¶
type Options struct {
// Filters run in order before the built-in mapping.
Filters []Filter
// LogClientErrors logs 4xx responses too. Off by default: a thousand
// validation failures a minute is a client bug, and logging them buries
// the server bugs.
LogClientErrors bool
}
Options configures the error handler.