From 111cf2d21ab3a2b7af5f8cfff3f6c1e5ab9d438e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E4=BA=AE?= Date: Wed, 4 Sep 2019 19:30:35 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E5=BC=82=E5=B8=B8=E6=94=B6=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/route/middleware/exception/exception.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/route/middleware/exception/exception.go b/app/route/middleware/exception/exception.go index 94ebc123..88d6c451 100644 --- a/app/route/middleware/exception/exception.go +++ b/app/route/middleware/exception/exception.go @@ -7,7 +7,6 @@ import ( "go-gin-api/app/util" "runtime/debug" "strings" - "time" ) func SetUp() gin.HandlerFunc { @@ -15,15 +14,24 @@ func SetUp() gin.HandlerFunc { return func(c *gin.Context) { defer func() { if err := recover(); err != nil { - subject := fmt.Sprintf("[Panic - %s] 项目出错了!", config.AppName) - body := fmt.Sprintf("错误时间:%s\n Runtime:\n%s",time.Now().Format("2006/01/02 - 15:04:05"), string(debug.Stack())) + subject := fmt.Sprintf("【重要错误】%s 项目出错了!", config.AppName) + + body := fmt.Sprintf("ErrorMessage: %s \n", err) + body += fmt.Sprintf("RequestTime: %s \n", util.GetCurrentDate()) + body += fmt.Sprintf("RequestURL: %s %s \n", c.Request.Method, c.Request.RequestURI) + body += fmt.Sprintf("RequestProto: %s \n", c.Request.Proto) + body += fmt.Sprintf("RequestReferer: %s \n", c.Request.Referer()) + body += fmt.Sprintf("RequestUA: %s \n", c.Request.UserAgent()) + body += fmt.Sprintf("RequestClientIp: %s \n", c.ClientIP()) + body += fmt.Sprintf("DebugStack: %s \n", string(debug.Stack())) + bodyHtml := "" - for _,v := range strings.Split(body, "\n") { + for _, v := range strings.Split(body, "\n") { bodyHtml += v + "
" } _ = util.SendMail(config.ErrorNotifyUser, subject, bodyHtml) - utilGin := util.Gin{Ctx:c} + utilGin := util.Gin{Ctx: c} utilGin.Response(500, "系统异常,请联系管理员!", nil) } }()