a842af2405
Stop exposing raw reason codes like admin_not_found in TOTP setup errors; auth routes and JWT guard now use Chinese literals with auth_failure_detail. Co-authored-by: Cursor <cursoragent@cursor.com>
1.2 KiB
1.2 KiB
2026-06-09 — HTTP API detail 英文改中文(全局层)
变更摘要
管理端 API 的 HTTPException.detail 经全局 handler 译为中文;/api/agent/* 保持英文(Agent 协议兼容)。
动机
Backlog「~75 条 API detail 英文」:422 已由 validation_errors_zh.py 覆盖,但 400/401/404 等仍返回 Server not found 等英文字面量。
涉及文件
server/utils/http_errors_zh.py(新)— 精确映射 + 正则(如 immutable setting、command exit)server/main.py—StarletteHTTPExceptionhandler 调用translate_http_detailtests/test_http_errors_zh.py
迁移 / 重启
需重启 API / 重建镜像。
验证
pytest tests/test_http_errors_zh.py tests/test_validation_errors_zh.py -q
# 示例:GET /api/servers/999999 → detail「服务器不存在」
后续(同批追加)
auth.py/auth_jwt.py:fallback 与字面量改中文;auth_failure_detail()映射reason码(避免返回admin_not_found)auth_service.py:setup_totp/enable_totp失败路径补message
仍待
- 其它模块
str(exc)透传 - 非 auth 路由字面量可逐步改源码或补
_DETAIL_EXACT