mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-16 04:50:41 +08:00
初次提交
This commit is contained in:
26
route/middle/panic.go
Normal file
26
route/middle/panic.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package middle
|
||||
|
||||
import (
|
||||
"msm/consts/ctxflag"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func PanicMiddle() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err == 0 {
|
||||
if err, ok := c.Get(ctxflag.ERR); ok {
|
||||
rErr(c, -1, err.(error).Error(), err.(error))
|
||||
} else {
|
||||
rErr(c, -1, "内部错误", nil)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
c.Next()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user