0 Star 1 Fork 0

有点心急 / gotls

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
error.go 692 Bytes
一键复制 编辑 原始数据 按行查看 历史
有点心急 提交于 2024-05-17 15:51 . 24.05.17
package middleware
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"gitee.com/Jiudan0905/go-tools/baseT/logT"
)
type CustomError struct {
Code int
Msg string
Log string
}
// 错误处理
func ErrorHandler() gin.HandlerFunc {
return gin.RecoveryWithWriter(nil, func(ctx *gin.Context, err any) {
if e, ok := err.(CustomError); ok {
logT.Log(fmt.Sprintf("msg: %s log: %s", e.Msg, e.Log))
ctx.JSON(http.StatusOK, gin.H{
"status_code": e.Code,
"status_msg": e.Msg,
})
} else {
ctx.JSON(http.StatusOK, gin.H{
"status_code": 500,
"status_msg": "unknown error, please contact the administrator",
})
}
// 中断请求
ctx.Abort()
})
}
Go
1
https://gitee.com/ydxj/gotls.git
git@gitee.com:ydxj/gotls.git
ydxj
gotls
gotls
v0.0.7

搜索帮助