From 60dcd37901a865feb7a11e9cd70e2afe7ca2ae82 Mon Sep 17 00:00:00 2001 From: black1552 Date: Tue, 3 Feb 2026 15:09:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E4=BF=AE=E5=A4=8DSave=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=92=8Cpanic=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将Save方法中的Model操作从Save改为Create - 更新panic日志格式,改进错误信息显示 - 修改错误响应消息为实际panic错误内容 --- curd/curd.go | 2 +- middleware/middleware.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/curd/curd.go b/curd/curd.go index 2f67213..45051cd 100644 --- a/curd/curd.go +++ b/curd/curd.go @@ -455,7 +455,7 @@ func (c Curd[R]) Count(ctx ctx, where any) (count int64) { // -------------------------- 原Save对应实现:新增/更新记录(对应GORM的Save) -------------------------- func (c Curd[R]) Save(ctx ctx, data any) { - err := c.Dao.Ctx(ctx).Model(new(R)).Save(data).Error + err := c.Dao.Ctx(ctx).Model(new(R)).Create(data).Error if err != nil { panic(fmt.Sprintf("Save保存错误: %v", err)) } diff --git a/middleware/middleware.go b/middleware/middleware.go index d4b142b..0cc9ab2 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -12,8 +12,8 @@ func ErrorHandler() gin.HandlerFunc { return func(c *gin.Context) { defer func() { if err := recover(); err != nil { - log.Error("发生panic", "path", c.Request.URL.Path, "method", c.Request.Method, err) - response.Error(c).SetCode(http.StatusInternalServerError).SetMsg("服务器内部错误").End() + log.Error("发生panic=》", "path:", c.Request.URL.Path, ",method:", c.Request.Method, ",", err) + response.Error(c).SetCode(http.StatusInternalServerError).SetMsg(err.(error).Error()).End() c.Abort() } }()