-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
Description
It seems that the whole fiber-middleware package was fully copied from gin-middleware.
Unlike gin, fiber explicitly returns errors in handlers and does not have neither ctx.Abort() or ctx.Error() method
// fiber.go
// Handler defines a function to serve HTTP requests.
type Handler = func(*Ctx) errorfibermiddleware.Options has ErrorHandler field, but it does not return error as it was designed for gin.Context.Abort() or gin.Context.Error() method call inside.
ErrorHandler should
- Pass error instead of string so that developers could use
errors.As/Is. - Return error in order to handle it by fiber middlewares
Code example:
type ErrorHandler func(c *fiber.Ctx, err error, statusCode int) error
...
err := ValidateRequestFromContext(c, router, options)
if err != nil {
if options != nil && options.ErrorHandler != nil {
return options.ErrorHandler(c, err, http.StatusBadRequest)
} else {
return fiber.NewError(http.StatusBadRequest, err.Error())
}
}