refactor: 错误消息脱敏 + 后端 CI
- 新增 utils.InternalMsg:内部错误详情只进服务端日志,对外统一脱敏 消息,不再向客户端泄露 GORM/SQL 实现细节;九个 controller 的 err.Error() 出口全部切换 - 新增 .github/workflows/ci.yml:go build/vet/test(backend,go 1.25)
This commit is contained in:
1 parent
1a47dee63d
commit
e0cef06234
11 files changed
+92
-49
No files matched your search
@@ -43,7 +43,7 @@ func (ctrl *PlanController) GetByProduct(c *gin.Context) {
|
||||
productID, _ := strconv.ParseUint(c.Param("product_id"), 10, 32)
|
||||
plans, err := ctrl.svc.GetByProduct(uint(productID))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"code": 0, "data": plans})
|
||||
@@ -69,7 +69,7 @@ func (ctrl *PlanController) Create(c *gin.Context) {
|
||||
}
|
||||
plan, err := ctrl.svc.Create(req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
utils.LogAction(ctrl.db, c, "create", "plan", plan.ID, plan.Name, "", "", "创建定价计划")
|
||||
@@ -95,7 +95,7 @@ func (ctrl *PlanController) Update(c *gin.Context) {
|
||||
}
|
||||
plan, err := ctrl.svc.Update(uint(id), req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
utils.LogAction(ctrl.db, c, "update", "plan", plan.ID, plan.Name, "", "", "更新定价计划")
|
||||
@@ -106,7 +106,7 @@ func (ctrl *PlanController) Update(c *gin.Context) {
|
||||
func (ctrl *PlanController) Delete(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 32)
|
||||
if err := ctrl.svc.Delete(uint(id)); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
utils.LogAction(ctrl.db, c, "delete", "plan", uint(id), "", "", "", "删除定价计划")
|
||||
@@ -121,7 +121,7 @@ func (ctrl *PlanController) ToggleStatus(c *gin.Context) {
|
||||
}
|
||||
c.ShouldBindJSON(&req)
|
||||
if err := ctrl.svc.ToggleStatus(uint(id), req.Status); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"code": 1, "message": utils.InternalMsg(err)})
|
||||
return
|
||||
}
|
||||
utils.LogAction(ctrl.db, c, "toggle_status", "plan", uint(id), "", "", "", "切换计划状态")
|
||||
|
||||
Reference in new issue
Block a user