fix(core): 修复Save方法和panic错误处理

- 将Save方法中的Model操作从Save改为Create
- 更新panic日志格式,改进错误信息显示
- 修改错误响应消息为实际panic错误内容
main v1.0.00012
black1552 2026-02-03 15:09:41 +08:00
parent b704eee2bc
commit 60dcd37901
2 changed files with 3 additions and 3 deletions

View File

@ -455,7 +455,7 @@ func (c Curd[R]) Count(ctx ctx, where any) (count int64) {
// -------------------------- 原Save对应实现新增/更新记录对应GORM的Save -------------------------- // -------------------------- 原Save对应实现新增/更新记录对应GORM的Save --------------------------
func (c Curd[R]) Save(ctx ctx, data any) { 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 { if err != nil {
panic(fmt.Sprintf("Save保存错误: %v", err)) panic(fmt.Sprintf("Save保存错误: %v", err))
} }

View File

@ -12,8 +12,8 @@ func ErrorHandler() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Error("发生panic", "path", c.Request.URL.Path, "method", c.Request.Method, err) log.Error("发生panic=》", "path", c.Request.URL.Path, ",method:", c.Request.Method, ",", err)
response.Error(c).SetCode(http.StatusInternalServerError).SetMsg("服务器内部错误").End() response.Error(c).SetCode(http.StatusInternalServerError).SetMsg(err.(error).Error()).End()
c.Abort() c.Abort()
} }
}() }()