This commit is contained in:
2026-08-10 18:45:26 +08:00
parent 190cf54f0f
commit 487c15779d
@@ -98,9 +98,14 @@ class RequestEncryptMiddleware(BaseHTTPMiddleware):
status_code=response.status_code, status_code=response.status_code,
headers={"X-Encrypted": "true", "Content-Type": "application/json"}, headers={"X-Encrypted": "true", "Content-Type": "application/json"},
) )
except HTTPException: except HTTPException as http_exc:
# 让 HTTPException(如 409 订单占用)正常传播,不被加密中间件拦截 # BaseHTTPMiddleware 中 call_next 抛出的 HTTPException 会直接传播,
raise # 这里捕获后返回对应状态码的响应,避免被外层 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: except Exception:
logger.exception("Request decryption failed") logger.exception("Request decryption failed")
return Response( return Response(