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}
@@ -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(
+4 -1
View File
@@ -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,
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -27,7 +27,7 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<title>民众智创</title>
<script type="module" crossorigin src="/assets/index-CFnMIoCK.js"></script>
<script type="module" crossorigin src="/assets/index-D088jE8K.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DtYH0-uL.css">
</head>
<body>
+3 -3
View File
@@ -90,11 +90,11 @@ const InvoicePage: React.FC = () => {
endDate: orderDateFilter[1] || undefined,
});
const items = data.items || [];
// 后端返回 is_occupied occupied_by直接使用
// 后端返回 is_occupied / occupied_byAPI 客户端转为 camelCase
const markedItems = items.map((o: any) => ({
...o,
_occupied: !!o.is_occupied,
_occupiedBy: o.occupied_by,
_occupied: !!o.isOccupied,
_occupiedBy: o.occupiedBy,
}));
setOrderData(markedItems);
setOrderTotal(data.total || 0);