Skip to main content
Version: Next

Recover

Recover middleware for Fiber that recovers from panics anywhere in the stack chain and handles the control to the centralized ErrorHandler.

Signatures

func New(config ...Config) fiber.Handler

Examples

Import the middleware package that is part of the Fiber web framework

import (
"github.com/gofiber/fiber/v3"
recoverer "github.com/gofiber/fiber/v3/middleware/recover"
)

After you initiate your Fiber app, you can use the following possibilities:

// Initialize default config
app.Use(recoverer.New())

// This panic will be caught by the middleware
app.Get("/", func(c fiber.Ctx) error {
panic("I'm an error")
})

Config

PropertyTypeDescriptionDefault
Nextfunc(fiber.Ctx) boolNext defines a function to skip this middleware when returned true.nil
EnableStackTraceboolEnableStackTrace enables handling stack trace.false
StackTraceHandlerfunc(fiber.Ctx, any)StackTraceHandler defines a function to handle stack trace.defaultStackTraceHandler

Default Config

var ConfigDefault = Config{
Next: nil,
EnableStackTrace: false,
StackTraceHandler: defaultStackTraceHandler,
}