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

Table of Contents

Signatures

1
func New(config ...Config) fiber.Handler
Copied!

Examples

Import the middleware package that is part of the Fiber web framework
1
import (
2
"github.com/gofiber/fiber/v2"
3
"github.com/gofiber/fiber/v2/middleware/recover"
4
)
Copied!
After you initiate your Fiber app, you can use the following possibilities:
1
// Default middleware config
2
app.Use(recover.New())
3
​
4
// This panic will be catch by the middleware
5
app.Get("/", func(c *fiber.Ctx) error {
6
panic("I'm an error")
7
})
Copied!

Config

1
// Config defines the config for middleware.
2
type Config struct {
3
// Next defines a function to skip this middleware when returned true.
4
//
5
// Optional. Default: nil
6
Next func(c *fiber.Ctx) bool
7
​
8
// EnableStackTrace enables handling stack trace
9
//
10
// Optional. Default: false
11
EnableStackTrace bool
12
​
13
// StackTraceHandler defines a function to handle stack trace
14
//
15
// Optional. Default: defaultStackTraceHandler
16
StackTraceHandler func(e interface{})
17
}
Copied!

Default Config

1
var ConfigDefault = Config{
2
Next: nil,
3
EnableStackTrace: false,
4
StackTraceHandler: defaultStackTraceHandler,
5
}
Copied!
Last modified 7mo ago