fix: fixed bug for gorm insert record failed and Error is not nil

This commit is contained in:
RockYang 2024-01-08 18:10:32 +08:00
parent fe85c1bbb9
commit 8a8990b12b
2 changed files with 4 additions and 4 deletions

View File

@ -157,7 +157,7 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
Prompt: prompt, Prompt: prompt,
CreatedAt: time.Now(), CreatedAt: time.Now(),
} }
if res := h.db.Create(&job); res.Error != nil { if res := h.db.Create(&job); res.Error != nil || res.RowsAffected == 0 {
resp.ERROR(c, "添加任务失败:"+res.Error.Error()) resp.ERROR(c, "添加任务失败:"+res.Error.Error())
return return
} }
@ -215,7 +215,7 @@ func (h *MidJourneyHandler) Upscale(c *gin.Context) {
Prompt: data.Prompt, Prompt: data.Prompt,
CreatedAt: time.Now(), CreatedAt: time.Now(),
} }
if res := h.db.Create(&job); res.Error != nil { if res := h.db.Create(&job); res.Error != nil || res.RowsAffected == 0 {
resp.ERROR(c, "添加任务失败:"+res.Error.Error()) resp.ERROR(c, "添加任务失败:"+res.Error.Error())
return return
} }
@ -264,7 +264,7 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) {
Prompt: data.Prompt, Prompt: data.Prompt,
CreatedAt: time.Now(), CreatedAt: time.Now(),
} }
if res := h.db.Create(&job); res.Error != nil { if res := h.db.Create(&job); res.Error != nil || res.RowsAffected == 0 {
resp.ERROR(c, "添加任务失败:"+res.Error.Error()) resp.ERROR(c, "添加任务失败:"+res.Error.Error())
return return
} }

View File

@ -232,7 +232,7 @@ func (h *PaymentHandler) PayQrcode(c *gin.Context) {
Remark: utils.JsonEncode(remark), Remark: utils.JsonEncode(remark),
} }
res = h.db.Create(&order) res = h.db.Create(&order)
if res.Error != nil { if res.Error != nil || res.RowsAffected == 0 {
resp.ERROR(c, "error with create order: "+res.Error.Error()) resp.ERROR(c, "error with create order: "+res.Error.Error())
return return
} }