refactor🎨: catch exception return error message

捕获runtime.Error异常,否则接口报错不返回任何信息
This commit is contained in:
wenjianzhang authored and GitHub committed 2022-08-18 10:14:12 +08:00
commit 60fe272ba0
1 file changed
+7 -1
+7 -1
View File
@@ -3,6 +3,7 @@ package middleware
import (
"fmt"
"net/http"
"runtime"
"strconv"
"strings"
"time"
@@ -43,9 +44,14 @@ func CustomError(c *gin.Context) {
} else {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "未知异常,请联系管理员!",
"msg": errStr,
})
}
case runtime.Error:
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": errStr.Error(),
})
default:
panic(err)
}