fixed: go-api => 增加全局错误处理 handler,修复业务处理异常导致服务退出的 Bug

This commit is contained in:
RockYang
2023-06-25 11:34:55 +08:00
parent 399a16fa28
commit 2c172c0851
5 changed files with 18 additions and 12 deletions

View File

@@ -72,7 +72,7 @@ func (s *AppServer) Run(db *gorm.DB) error {
func errorHandler(c *gin.Context) {
defer func() {
if r := recover(); r != nil {
logger.Error("panic: %v\n", r)
logger.Error("Handler Panic: %v\n", r)
debug.PrintStack()
c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: types.ErrorMsg})
c.Abort()