修复(#4): 抽奖 8 宫格默认值 + 100500 msg 脱敏
Closes part of HIF-4 (Stage 2 前端集成反馈 F8 + F10) F8 (P1): Activity.GridSize 默认值 9 → 8 - migration 02160 ALTER DEFAULT 8(幂等) - 02156 up.sql 注释同步更新 - admin/lottery.go 兜底值 9 → 8 - 布局 A:3x3 挖中心,中心是抽奖按钮不是奖品 F10 (P1): wrapInternal msg 脱敏 - 内部错误 err.Error() 只写日志,不外传 - 用户端 msg 只带通用文案 (xerr.MapErrMsg lookup) - 回归护栏:TestWrapInternal_ScrubsErrorDetailsFromMsg + TestWrapInternal_PreservesCodeErrors CI 全绿;无 API 契约变更;F9 独立在 PR #45 处理
This commit is contained in:
@@ -38,6 +38,7 @@ import (
|
||||
"github.com/perfect-panel/server/internal/logic/lottery/handler"
|
||||
"github.com/perfect-panel/server/internal/model/lottery"
|
||||
"github.com/perfect-panel/server/pkg/limit"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -601,15 +602,24 @@ func parseEligibilityTree(raw string) (*lottery.EligibilityRule, error) {
|
||||
return &tree, nil
|
||||
}
|
||||
|
||||
// wrapInternal 把内部 error 转成对外的 LotteryInternalError code。
|
||||
//
|
||||
// HIF-4 F10:msg 字段只带通用文案("抽奖服务暂时不可用"),err.Error() 的原文
|
||||
// 只写日志,绝不外泄给 app 端。之前把 err.Error() 直接塞 msg 导致
|
||||
// {"code":100500,"msg":"insert lottery_claim for draw 15: Error 3140 ..."} 这种
|
||||
// 响应,泄露 DB 结构 + 撑爆前端 msg 字段。
|
||||
func wrapInternal(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
// Preserve already-coded errors.
|
||||
// Preserve already-coded errors (their msg 是设计过的对外文案,不动).
|
||||
if _, ok := err.(*xerr.CodeError); ok {
|
||||
return err
|
||||
}
|
||||
return xerr.NewErrCodeMsg(xerr.LotteryInternalError, err.Error())
|
||||
// 内部细节走日志,供运维/后端排查;err.Error() 不外传。
|
||||
logger.WithContext(context.Background()).Error("[lottery draw internal error]",
|
||||
logger.Field("error", err.Error()))
|
||||
return xerr.NewErrCode(xerr.LotteryInternalError)
|
||||
}
|
||||
|
||||
// ---- Rate limiter production wiring ----------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user