Recover middleware for Fiber that recovers from panics anywhere in the stack chain and handles the control to the centralized ErrorHandler.
func New(config ...Config) fiber.Handler
Import the middleware package that is part of the Fiber web framework
import ("github.com/gofiber/fiber/v2""github.com/gofiber/fiber/v2/middleware/recover")
After you initiate your Fiber app, you can use the following possibilities:
// Default middleware configapp.Use(recover.New())// This panic will be catch by the middlewareapp.Get("/", func(c *fiber.Ctx) error {panic("I'm an error")})
// Config defines the config for middleware.type Config struct {// Next defines a function to skip this middleware when returned true.//// Optional. Default: nilNext func(c *fiber.Ctx) bool// EnableStackTrace enables handling stack trace//// Optional. Default: falseEnableStackTrace bool// StackTraceHandler defines a function to handle stack trace//// Optional. Default: defaultStackTraceHandlerStackTraceHandler func(e interface{})}
var ConfigDefault = Config{Next: nil,EnableStackTrace: false,StackTraceHandler: defaultStackTraceHandler,}