1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 17:03:42 +00:00
2020-11-11 14:03:16 +01:00
..
2020-11-11 14:03:16 +01:00
v2
2020-09-13 11:20:11 +02:00
2020-09-17 13:41:06 +08:00
2020-11-11 14:03:16 +01:00

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

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

Examples

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 config
app.Use(recover.New())

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

Config

// Config defines the config for middleware.
type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c *fiber.Ctx) bool
}

Default Config

var ConfigDefault = Config{
	Next: nil,
}