1
0
Fork 0

에러 처리 완료

This commit is contained in:
Sangbum Kim 2016-03-15 23:59:16 +09:00
parent 84ec23420d
commit 2464a48b1c
1 changed files with 6 additions and 12 deletions

View File

@ -59,18 +59,12 @@ func recoveryError(code int, c *gin.Context) map[string]interface{} {
func RecoveryHttpError(code int) gin.HandlerFunc { func RecoveryHttpError(code int) gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
info := recoveryError(code, c) info := recoveryError(code, c)
if strings.HasPrefix(c.Request.URL.Path, "/api") { if strings.HasPrefix(c.Request.URL.Path, "/api") {
c.JSON(code, gin.H(info)) c.JSON(code, gin.H(info))
} else { } else {
c.HTML(code, "page_404.html", template.Context(info)) c.HTML(code, "page_404.html", template.Context(info))
} }
c.Abort()
}
}()
c.Next()
} }
} }
func RecoveryJSON() gin.HandlerFunc { func RecoveryJSON() gin.HandlerFunc {