1
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user