framework1/framework/middleware/recovery.go

18 lines
294 B
Go
Raw Normal View History

2024-10-18 14:41:55 +08:00
package middleware
import (
2024-10-18 17:21:19 +08:00
"github.com/Superdanda/hade/framework/gin"
2024-10-18 14:41:55 +08:00
"net/http"
)
2024-10-18 17:21:19 +08:00
func Recovery() gin.HandlerFunc {
return func(c *gin.Context) {
2024-10-18 14:41:55 +08:00
defer func() {
if err := recover(); err != nil {
2024-10-18 17:21:19 +08:00
c.ISetStatus(http.StatusInternalServerError).IJson(err)
2024-10-18 14:41:55 +08:00
}
}()
c.Next()
}
}