github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/recover.md (about) 1 --- 2 id: recover 3 title: Recover 4 --- 5 6 Recover middleware for [Fiber](https://github.com/gofiber/fiber) that recovers from panics anywhere in the stack chain and handles the control to the centralized [ErrorHandler](https://docs.gofiber.io/error-handling). 7 8 ## Signatures 9 10 ```go 11 func New(config ...Config) fiber.Handler 12 ``` 13 14 ## Examples 15 16 Import the middleware package that is part of the Fiber web framework 17 18 ```go 19 import ( 20 "github.com/gofiber/fiber/v2" 21 "github.com/gofiber/fiber/v2/middleware/recover" 22 ) 23 ``` 24 25 After you initiate your Fiber app, you can use the following possibilities: 26 27 ```go 28 // Initialize default config 29 app.Use(recover.New()) 30 31 // This panic will be caught by the middleware 32 app.Get("/", func(c *fiber.Ctx) error { 33 panic("I'm an error") 34 }) 35 ``` 36 37 ## Config 38 39 ```go 40 // Config defines the config for middleware. 41 type Config struct { 42 // Next defines a function to skip this middleware when returned true. 43 // 44 // Optional. Default: nil 45 Next func(c *fiber.Ctx) bool 46 47 // EnableStackTrace enables handling stack trace 48 // 49 // Optional. Default: false 50 EnableStackTrace bool 51 52 // StackTraceHandler defines a function to handle stack trace 53 // 54 // Optional. Default: defaultStackTraceHandler 55 StackTraceHandler func(c *fiber.Ctx, e interface{}) 56 } 57 ``` 58 59 ## Default Config 60 61 ```go 62 var ConfigDefault = Config{ 63 Next: nil, 64 EnableStackTrace: false, 65 StackTraceHandler: defaultStackTraceHandler, 66 } 67 ```