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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -43,9 +44,14 @@ func CustomError(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"code": 500,
|
"code": 500,
|
||||||
"msg": "未知异常,请联系管理员!",
|
"msg": errStr,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
case runtime.Error:
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"msg": errStr.Error(),
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user