refactor(core): 1062 唯一键冲突判定收口至 core/db_errors

六个 service 各自复制的 _is_duplicate_entry(口径已漂移:rating/product
用 _ERR_DUP_ENTRY 常量、其余四处写字面量 1062)收敛为共享函数;
is_duplicate_entry 语义与文案注释各处保留,非 1062 完整性错误仍原样
上抛由全局处理器收敛。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
liuwenxinandClaude Code committed 2026-10-14 15:17:00 +08:00
1 parent 5a3778a424
commit a0086554b1
7 files changed
+31 -19

No files matched your search

+2 -2
View File
@@ -35,6 +35,7 @@ from app.core.constants import (
MODULE_RECEIPT,
NO_PREFIX_RECEIPT,
)
from app.core.db_errors import is_duplicate_entry
from app.core.exceptions import BadRequestError, NotFoundError
from app.core.response import PageResult
from app.models import Receipt
@@ -342,5 +343,4 @@ def delete_receipt(
def _is_duplicate_entry(exc: IntegrityError) -> bool:
"""识别 MySQL 唯一键冲突(1062),与 business_service 同口径。"""
args = getattr(exc.orig, "args", ())
return bool(args) and args[0] == 1062
return is_duplicate_entry(exc)