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}
|
||||
|
||||
@@ -98,14 +98,6 @@ class RequestEncryptMiddleware(BaseHTTPMiddleware):
|
||||
status_code=response.status_code,
|
||||
headers={"X-Encrypted": "true", "Content-Type": "application/json"},
|
||||
)
|
||||
except HTTPException as http_exc:
|
||||
# BaseHTTPMiddleware 中 call_next 抛出的 HTTPException 会直接传播,
|
||||
# 这里捕获后返回对应状态码的响应,避免被外层 except Exception 吞掉
|
||||
return Response(
|
||||
content=json.dumps({"detail": http_exc.detail}, ensure_ascii=False),
|
||||
status_code=http_exc.status_code,
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Request decryption failed")
|
||||
return Response(
|
||||
|
||||
@@ -88,7 +88,10 @@ async def create_invoice(
|
||||
# 2. 检查订单唯一性
|
||||
occupied = await check_orders_available(db, data.order_ids)
|
||||
if occupied:
|
||||
details = f"订单 {order.order_no} 未支付,无法开票",
|
||||
details = "; ".join(
|
||||
f"订单 {o['order_no']} 已被发票 {o['invoice_no']} 占用"
|
||||
for o in occupied
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail=details,
|
||||
|
||||
Reference in New Issue
Block a user