This commit is contained in:
2026-08-10 19:05:07 +08:00
parent 0e47719d5c
commit 5bcc7888c2
6 changed files with 14 additions and 15 deletions
+5 -1
View File
@@ -635,7 +635,11 @@ def create_app() -> FastAPI:
async def v3_http_exception_handler(request: Request, exc: HTTPException):
"""仅对 /api/v3/ 路径返回统一格式,HTTP 状态码固定 200。"""
if not str(request.url.path).startswith("/api/v3"):
raise exc # 交给其他处理器
# 非 v3 路径返回标准 HTTPException 响应,保持原始状态码
return JSONResponse(
status_code=exc.status_code,
content={"detail": exc.detail},
)
detail = exc.detail
message = detail.get("message", str(detail)) if isinstance(detail, dict) else str(detail)
code_map = {400: 40000, 401: 40100, 403: 40300, 404: 40400, 429: 42900, 422: 42200, 500: 50000, 504: 50400}