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
@@ -77,7 +77,7 @@ func (ctrl *ProductController) GetByCode(c *gin.Context) {
|
||||
}
|
||||
plans, err := ctrl.planSvc.GetByProduct(product.ID)
|
||||
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": dto.ProductWithPlansResponse{
|
||||
@@ -95,7 +95,7 @@ func (ctrl *ProductController) Create(c *gin.Context) {
|
||||
}
|
||||
product, 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", "product", product.ID, product.Name, "", "", "创建产品")
|
||||
@@ -112,7 +112,7 @@ func (ctrl *ProductController) Update(c *gin.Context) {
|
||||
}
|
||||
product, 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", "product", product.ID, product.Name, "", "", "更新产品")
|
||||
@@ -123,7 +123,7 @@ func (ctrl *ProductController) Update(c *gin.Context) {
|
||||
func (ctrl *ProductController) 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", "product", uint(id), "", "", "", "删除产品")
|
||||
@@ -138,7 +138,7 @@ func (ctrl *ProductController) UpdateStatus(c *gin.Context) {
|
||||
}
|
||||
c.ShouldBindJSON(&req)
|
||||
if err := ctrl.svc.UpdateStatus(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, "update_status", "product", uint(id), "", "", "", fmt.Sprintf("切换状态为 %d", req.Status))
|
||||
@@ -156,7 +156,7 @@ func (ctrl *ProductController) BatchDelete(c *gin.Context) {
|
||||
}
|
||||
result, err := ctrl.svc.BatchDelete(req.IDs)
|
||||
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, "batch_delete", "product", 0, "", "", "",
|
||||
|
||||
Reference in new issue
Block a user