fix(api): 错误提示 - 将业务冲突与校验信息本地化

This commit is contained in:
ddcat666 committed 2026-09-29 08:27:03 +08:00
1 parent 98bc434693
commit 7b26f7f150
13 files changed
+44 -44

No files matched your search

+2 -2
View File
@@ -6,8 +6,8 @@ import (
) )
var ( var (
ErrInvalidTokenBilling = errors.New("invalid token billing parameters") ErrInvalidTokenBilling = errors.New("按量计费参数无效")
ErrTokenBillingOverflow = errors.New("token billing amount overflows int64") ErrTokenBillingOverflow = errors.New("按量计费金额超出上限")
) )
type TokenBillingTerm struct { type TokenBillingTerm struct {
+3 -3
View File
@@ -11,9 +11,9 @@ import (
) )
var ( var (
ErrBulkUserNotFound = errors.New("bulk user not found") ErrBulkUserNotFound = errors.New("所选用户中有不存在的账号")
ErrBulkCurrentAdmin = errors.New("bulk includes current admin") ErrBulkCurrentAdmin = errors.New("批量操作不能包含当前管理员自己")
ErrBulkLastActiveAdmin = errors.New("bulk removes last active admin") ErrBulkLastActiveAdmin = errors.New("不能移除最后一个可用的管理员")
) )
type AdminUserCounts struct { type AdminUserCounts struct {
@@ -9,9 +9,9 @@ import (
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
) )
var ErrAdminResourceDeleteChanged = errors.New("admin resource delete set changed") var ErrAdminResourceDeleteChanged = errors.New("待删除的资源已变化,请刷新后重试")
var ErrAdminResourceStillReferenced = errors.New("admin resource is still directly referenced") var ErrAdminResourceStillReferenced = errors.New("资源仍被引用,无法删除")
var ErrAdminResourceAuditMismatch = errors.New("admin resource delete audit mismatch") var ErrAdminResourceAuditMismatch = errors.New("资源删除记录不一致,请刷新后重试")
func (r *Repository) AdminResourcesByIDs(ids []string) ([]model.Resource, error) { func (r *Repository) AdminResourcesByIDs(ids []string) ([]model.Resource, error) {
if len(ids) == 0 { if len(ids) == 0 {
@@ -9,8 +9,8 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
var ErrAnnouncementImageDraftUnavailable = errors.New("announcement image draft unavailable") var ErrAnnouncementImageDraftUnavailable = errors.New("公告图片草稿已失效,请重新上传")
var ErrAnnouncementImageReferenced = errors.New("announcement image is still referenced") var ErrAnnouncementImageReferenced = errors.New("公告图片仍被引用,无法删除")
func (r *Repository) CreateAnnouncementImageDraft(draft *model.AnnouncementImageDraft) error { func (r *Repository) CreateAnnouncementImageDraft(draft *model.AnnouncementImageDraft) error {
return r.db.Create(draft).Error return r.db.Create(draft).Error
@@ -8,7 +8,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
var ErrChannelModelPriceConflict = errors.New("channel model prices changed concurrently") var ErrChannelModelPriceConflict = errors.New("模型价格已变化,请刷新后重试")
// UpdateChannelModelSalePrices commits the entire selection or nothing. Only // UpdateChannelModelSalePrices commits the entire selection or nothing. Only
// pricing columns are written; version checks protect the cost snapshot used by app. // pricing columns are written; version checks protect the cost snapshot used by app.
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"infinite-canvas/backend/internal/model" "infinite-canvas/backend/internal/model"
) )
var ErrCreationConflict = errors.New("creation state changed; reload before continuing") var ErrCreationConflict = errors.New("数据已被更新,请刷新后重试")
func (r *Repository) CreationStorageUsage(userID string) (int64, int64, error) { func (r *Repository) CreationStorageUsage(userID string) (int64, int64, error) {
var usage struct { var usage struct {
+8 -8
View File
@@ -17,14 +17,14 @@ import (
) )
var ( var (
ErrInsufficientCredits = errors.New("insufficient credits") ErrInsufficientCredits = errors.New("积分不足,请先充值")
ErrRedeemCodeInvalid = errors.New("redeem code invalid") ErrRedeemCodeInvalid = errors.New("兑换码无效或已使用")
ErrActiveTaskLimit = errors.New("active task limit reached") ErrActiveTaskLimit = errors.New("同时进行的任务数已达上限,请等待已有任务完成")
ErrTaskNotRetryable = errors.New("task is not retryable") ErrTaskNotRetryable = errors.New("该任务当前状态不支持重试")
ErrBillingStateConflict = errors.New("billing state conflict") ErrBillingStateConflict = errors.New("计费状态已变化,请刷新后重试")
ErrBillingUsageUnavailable = errors.New("billing usage unavailable") ErrBillingUsageUnavailable = errors.New("暂时无法获取用量,计费未完成")
ErrBillingChargeLimit = errors.New("billing amount exceeds authorized charge limit") ErrBillingChargeLimit = errors.New("本次费用超过授权上限,已拒绝扣费")
ErrChannelModelInUse = errors.New("channel model is in use") ErrChannelModelInUse = errors.New("该渠道模型正在被使用,无法删除或停用")
) )
// 先抢占唯一业务键再更新账户,确保注册和签到奖励在多实例并发下只入账一次。 // 先抢占唯一业务键再更新账户,确保注册和签到奖励在多实例并发下只入账一次。
@@ -17,8 +17,8 @@ type LogicalModelGraph struct {
ChannelModels []model.ChannelModel ChannelModels []model.ChannelModel
} }
var ErrLogicalModelInUse = errors.New("logical model is in use") var ErrLogicalModelInUse = errors.New("该模型正在被使用,无法删除或停用")
var ErrLogicalModelUnavailable = errors.New("logical model is unavailable") var ErrLogicalModelUnavailable = errors.New("所选模型已停用或不可用,请重新选择")
func (r *Repository) LogicalModels(includeDisabled bool) ([]model.LogicalModel, error) { func (r *Repository) LogicalModels(includeDisabled bool) ([]model.LogicalModel, error) {
var items []model.LogicalModel var items []model.LogicalModel
+3 -3
View File
@@ -8,9 +8,9 @@ import (
"time" "time"
) )
var ErrNotificationLimit = errors.New("notification limit reached") var ErrNotificationLimit = errors.New("通知发送次数已达上限,请稍后再试")
var ErrVerificationInvalid = errors.New("verification expired, changed or consumed") var ErrVerificationInvalid = errors.New("验证码已过期或已使用,请重新获取")
var ErrChannelConflict = errors.New("sms channel changed") var ErrChannelConflict = errors.New("短信通道配置已变化,请重新获取验证码")
func (r *Repository) AttemptLegacyEmailVerification(id string) error { func (r *Repository) AttemptLegacyEmailVerification(id string) error {
result := r.db.Model(&model.EmailVerificationCode{}).Where("id = ? AND attempts < 5 AND used_at IS NULL AND expires_at > ?", id, time.Now()).Update("attempts", gorm.Expr("attempts + 1")) result := r.db.Model(&model.EmailVerificationCode{}).Where("id = ? AND attempts < 5 AND used_at IS NULL AND expires_at > ?", id, time.Now()).Update("attempts", gorm.Expr("attempts + 1"))
+4 -4
View File
@@ -12,10 +12,10 @@ import (
) )
var ( var (
ErrPaymentOrderStateConflict = errors.New("payment order state conflict") ErrPaymentOrderStateConflict = errors.New("订单状态已变化,请刷新后重试")
ErrPaymentEvidenceMismatch = errors.New("payment evidence does not match order") ErrPaymentEvidenceMismatch = errors.New("支付凭证与订单不一致")
ErrPaymentTradeNoConflict = errors.New("payment provider trade number is already used") ErrPaymentTradeNoConflict = errors.New("该支付流水号已被使用")
ErrPaymentCreditOverflow = errors.New("payment credit balance would overflow") ErrPaymentCreditOverflow = errors.New("积分余额超出上限,无法入账")
) )
// Credit balances are serialized to JavaScript clients as JSON numbers. // Credit balances are serialized to JavaScript clients as JSON numbers.
@@ -20,7 +20,7 @@ type PaymentReconciliationFilter struct {
ProviderID, Status, From, To string ProviderID, Status, From, To string
} }
var ErrPaymentReconciliationRunning = errors.New("payment reconciliation is running") var ErrPaymentReconciliationRunning = errors.New("正在对账,请稍后再试")
func (r *Repository) paymentReconciliationItemsQuery(runID, result string) *gorm.DB { func (r *Repository) paymentReconciliationItemsQuery(runID, result string) *gorm.DB {
query := r.db.Model(&model.PaymentReconciliationItem{}).Where("run_id = ?", strings.TrimSpace(runID)) query := r.db.Model(&model.PaymentReconciliationItem{}).Where("run_id = ?", strings.TrimSpace(runID))
+12 -12
View File
@@ -17,27 +17,27 @@ import (
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
) )
var ErrDailyUploadLimitExceeded = errors.New("daily upload limit exceeded") var ErrDailyUploadLimitExceeded = errors.New("今日上传额度已用完,请明天再试")
var ErrTaskProviderRecoveryConflict = errors.New("task provider recovery is already running") var ErrTaskProviderRecoveryConflict = errors.New("任务正在恢复中,请稍后查看")
var ErrTaskProviderCancellationConflict = errors.New("task provider cancellation is already claimed") var ErrTaskProviderCancellationConflict = errors.New("任务正在取消中,请稍后查看")
var ErrTaskStateConflict = errors.New("task state changed concurrently") var ErrTaskStateConflict = errors.New("任务状态已变化,请刷新后重试")
var ErrTextReplayQuotaExceeded = errors.New("text replay quota exceeded") var ErrTextReplayQuotaExceeded = errors.New("文本回放额度已用完")
var ErrTextReplayClosed = errors.New("text replay task is closed") var ErrTextReplayClosed = errors.New("该文本任务已结束")
var ErrEmailVerificationCodeInvalid = errors.New("email verification code is no longer valid") var ErrEmailVerificationCodeInvalid = errors.New("邮箱验证码已失效,请重新获取")
var ErrProjectAssetFolderNotEmpty = errors.New("project asset folder is not empty") var ErrProjectAssetFolderNotEmpty = errors.New("资产文件夹不为空,无法删除")
var ErrProjectHasActiveTasks = errors.New("project has active tasks") var ErrProjectHasActiveTasks = errors.New("项目中还有进行中的任务,请等待完成后再操作")
var ErrProjectUnitShotsChanged = errors.New("project unit shots changed") var ErrProjectUnitShotsChanged = errors.New("镜头已被修改,请刷新后重试")
var ErrCanvasRevisionConflict = errors.New("canvas revision changed") var ErrCanvasRevisionConflict = errors.New("画布已被更新,请刷新后重试")
type Repository struct { type Repository struct {
db *gorm.DB db *gorm.DB
@@ -282,7 +282,7 @@ func (r *Repository) CreateUserWithEmailVerification(user *model.User, verificat
return result.Error return result.Error
} }
if result.RowsAffected != 1 { if result.RowsAffected != 1 {
return errors.New("email verification code is no longer valid") return errors.New("邮箱验证码已失效,请重新获取")
} }
return tx.Create(user).Error return tx.Create(user).Error
}) })
@@ -10,8 +10,8 @@ import (
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
) )
var ErrResourceCleanupSetChanged = errors.New("resource cleanup set changed") var ErrResourceCleanupSetChanged = errors.New("待清理的资源已变化,请刷新后重试")
var ErrResourceCleanupStillReferenced = errors.New("resource cleanup resource is still directly referenced") var ErrResourceCleanupStillReferenced = errors.New("资源仍被引用,暂不清理")
// DeleteDetachedResources removes Resource rows and enqueues physical deletion in one transaction. // DeleteDetachedResources removes Resource rows and enqueues physical deletion in one transaction.
// JSON references are checked by the service before this call; direct foreign-key-like references // JSON references are checked by the service before this call; direct foreign-key-like references