This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
schisandra-cloud-album/middleware/exception_notification.go
2024-09-05 23:34:46 +08:00

41 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middleware
import (
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/messages"
ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin"
"schisandra-cloud-album/common/result"
"schisandra-cloud-album/global"
"schisandra-cloud-album/utils"
"time"
)
// ExceptionNotification 异常通知中间件
func ExceptionNotification() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
openID := global.CONFIG.Wechat.OpenID
content := `
系统异常通知:
请求时间:` + time.Now().Format("2006-01-02 15:04:05") + `
请求IP` + utils.GetClientIP(c) + `
请求地址:` + c.Request.URL.String() + `
请求方法:` + c.Request.Method + `
请求参数:` + c.Request.Form.Encode() + `
错误信息:` + err.(error).Error() + `
`
messages.NewRaw(`
{
"touser":"` + openID + `",
"msgtype":"text",
"text":{"content":"` + content + `"}"}
}
`)
result.FailWithMessage(ginI18n.MustGetMessage(c, "SystemError"), c)
}
}()
c.Next()
}
}