refactor🎨: catch exception return error message
捕获runtime.Error异常,否则接口报错不返回任何信息
This commit is contained in:
1 file changed
+7
-1
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user