3ba78cd10a
Add a global detail translator for common 4xx messages (Server not found, auth headers, settings not found, etc.) while keeping /api/agent/* in English. Co-authored-by: Cursor <cursoragent@cursor.com>
995 B
995 B
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「服务器不存在」
后续
- 新增英文字面量时补
_DETAIL_EXACT或改源码直接写中文 str(exc)透传类错误依赖下层异常已是中文