优化报错

This commit is contained in:
2025-10-23 11:52:08 +08:00
parent 324a533c94
commit af6a00ee47

View File

@@ -2,6 +2,7 @@ package management
import ( import (
"errors" "errors"
"fmt"
"strconv" "strconv"
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller" "git.huangwc.com/pig/pig-farm-controller/internal/app/controller"
@@ -25,7 +26,7 @@ func mapAndSendError(c *PigBatchController, ctx *gin.Context, action string, err
controller.SendErrorWithAudit(ctx, controller.CodeConflict, err.Error(), action, err.Error(), id) controller.SendErrorWithAudit(ctx, controller.CodeConflict, err.Error(), action, err.Error(), id)
} else { } else {
c.logger.Errorf("操作[%s]业务逻辑失败: %v", action, err) c.logger.Errorf("操作[%s]业务逻辑失败: %v", action, err)
controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "操作失败", action, err.Error(), id) controller.SendErrorWithAudit(ctx, controller.CodeInternalError, fmt.Sprintf("操作失败: %v", err), action, err.Error(), id)
} }
} }
@@ -156,7 +157,7 @@ func handleAPIRequestWithResponse[Req any, Resp any](
) { ) {
// 1. 绑定请求体 // 1. 绑定请求体
if err := ctx.ShouldBindJSON(&reqDTO); err != nil { if err := ctx.ShouldBindJSON(&reqDTO); err != nil {
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求体", action, "请求体绑定失败", reqDTO) controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, fmt.Sprintf("无效的请求体: %v", err), action, fmt.Sprintf("请求体绑定失败: %v", err), reqDTO)
return return
} }