에러 처리 완료
This commit is contained in:
parent
84ec23420d
commit
2464a48b1c
|
@ -59,18 +59,12 @@ func recoveryError(code int, c *gin.Context) map[string]interface{} {
|
|||
|
||||
func RecoveryHttpError(code int) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
info := recoveryError(code, c)
|
||||
if strings.HasPrefix(c.Request.URL.Path, "/api") {
|
||||
c.JSON(code, gin.H(info))
|
||||
} else {
|
||||
c.HTML(code, "page_404.html", template.Context(info))
|
||||
}
|
||||
c.Abort()
|
||||
}
|
||||
}()
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
func RecoveryJSON() gin.HandlerFunc {
|
||||
|
|
Loading…
Reference in New Issue