middleware: Add recovery middleware
This commit is contained in:
parent
3bf14b9c04
commit
e770731643
21
framework/middleware/recovery.go
Normal file
21
framework/middleware/recovery.go
Normal file
@ -0,0 +1,21 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||
)
|
||||
|
||||
// Recovery is a middleware that recovers from the panic
|
||||
func Recovery() framework.ControllerHandler {
|
||||
return func(c *framework.Context) error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
c.WriteJSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
}()
|
||||
|
||||
c.Next()
|
||||
return nil
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user