fix(core): 修复Save方法和panic错误处理
- 将Save方法中的Model操作从Save改为Create - 更新panic日志格式,改进错误信息显示 - 修改错误响应消息为实际panic错误内容main v1.0.00012
parent
b704eee2bc
commit
60dcd37901
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue