mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-23 21:08:09 +00:00
* refactor: 移除冗余的工具名称和描述,简化代码生成器的文档 * Add Content-Type to S3 upload input Add Content-Type to S3 upload input * style: 优化仪表盘组件样式,调整各个子组件的布局和样式,提升视觉效果 * fix: 更新插件链接 * 优化角色配置-首页配置相关内容 * feat: 默认首页只允许选择已选中的菜单 * feat: 更新样式和优化组件,调整背景色及文本颜色 * feat: 清理无用的右侧边线 * feat: 增加了导入导出模板的自定义sql能力,方便灵活化扩展导入导出 * feat: 优化日志输出,增加插件字典定义 * feat: 增加插件字典定义前端相关 * feat: 增加插件自定义字典方法 * feat: 增加文件名和路径合法性检查 * feat: 修复暗黑模式和亮色模式logo路径定义 * feat: 移除未使用的defineEmits导入 * feat: 更新授权链接至新地址 * feat: 移除菜单组件背景色 * feat: 更新导出和导入SQL语句的示例占位符 * feat: 错误日志必须有数据库链接才会存储 * feat: 移除仪表板中公告卡片的高度限制 * feat: 添加插件列表接口,更新插件表格组件,移除不必要的注释 * feat: 更新版本号至v2.8.8,调整插件表格组件的请求参数 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: Yexk_M <yexk@yexk.cn> Co-authored-by: Azir-11 <2075125282@qq.com>
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"os"
|
|
"runtime/debug"
|
|
"strings"
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/service"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// GinRecovery recover掉项目可能出现的panic,并使用zap记录相关日志
|
|
func GinRecovery(stack bool) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
// Check for a broken connection, as it is not really a
|
|
// condition that warrants a panic stack trace.
|
|
var brokenPipe bool
|
|
if ne, ok := err.(*net.OpError); ok {
|
|
if se, ok := ne.Err.(*os.SyscallError); ok {
|
|
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
|
|
brokenPipe = true
|
|
}
|
|
}
|
|
}
|
|
|
|
httpRequest, _ := httputil.DumpRequest(c.Request, false)
|
|
if brokenPipe {
|
|
global.GVA_LOG.Error(c.Request.URL.Path,
|
|
zap.Any("error", err),
|
|
zap.String("request", string(httpRequest)),
|
|
)
|
|
// If the connection is dead, we can't write a status to it.
|
|
_ = c.Error(err.(error)) // nolint: errcheck
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
if stack {
|
|
form := "后端"
|
|
info := fmt.Sprintf("Panic: %v\nRequest: %s\nStack: %s", err, string(httpRequest), string(debug.Stack()))
|
|
level := "error"
|
|
_ = service.ServiceGroupApp.SystemServiceGroup.SysErrorService.CreateSysError(context.Background(), &system.SysError{
|
|
Form: &form,
|
|
Info: &info,
|
|
Level: level,
|
|
})
|
|
global.GVA_LOG.Error("[Recovery from panic]",
|
|
zap.Any("error", err),
|
|
zap.String("request", string(httpRequest)),
|
|
)
|
|
} else {
|
|
form := "后端"
|
|
info := fmt.Sprintf("Panic: %v\nRequest: %s", err, string(httpRequest))
|
|
level := "error"
|
|
_ = service.ServiceGroupApp.SystemServiceGroup.SysErrorService.CreateSysError(context.Background(), &system.SysError{
|
|
Form: &form,
|
|
Info: &info,
|
|
Level: level,
|
|
})
|
|
global.GVA_LOG.Error("[Recovery from panic]",
|
|
zap.Any("error", err),
|
|
zap.String("request", string(httpRequest)),
|
|
)
|
|
}
|
|
c.AbortWithStatus(http.StatusInternalServerError)
|
|
}
|
|
}()
|
|
c.Next()
|
|
}
|
|
}
|