123456789101112131415161718192021222324 |
- package exception
- import (
- "exam_system/result"
- "fmt"
- "github.com/gin-gonic/gin"
- "net/http"
- "runtime/debug"
- )
- func Recover() gin.HandlerFunc {
- return func(c *gin.Context) {
- defer func() {
- if r := recover(); r != nil {
- fmt.Errorf("panic %v\n", r)
- debug.PrintStack()
- c.JSON(http.StatusInternalServerError, result.UNKNOW_ERROR.SetMsg(r.(error).Error()))
- c.Abort()
- }
- }()
- c.Next()
- }
- }
|