fa45d8aa5f
- health_checklist.json: 192.168.1.122→node122
- ocr_client.py: docstring IP→node122
- docs/market-data-requirements.md: IP→node122
- 所有API调用通过ProxyHandler({})绕过系统代理
Privoxy对node122:18003返回500,直连正常
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from fastapi.encoders import jsonable_encoder
|
|
from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
|
|
from fastapi.utils import is_body_allowed_for_status_code
|
|
from fastapi.websockets import WebSocket
|
|
from starlette.exceptions import HTTPException
|
|
from starlette.requests import Request
|
|
from starlette.responses import JSONResponse, Response
|
|
from starlette.status import WS_1008_POLICY_VIOLATION
|
|
|
|
|
|
async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
|
|
headers = getattr(exc, "headers", None)
|
|
if not is_body_allowed_for_status_code(exc.status_code):
|
|
return Response(status_code=exc.status_code, headers=headers)
|
|
return JSONResponse(
|
|
{"detail": exc.detail}, status_code=exc.status_code, headers=headers
|
|
)
|
|
|
|
|
|
async def request_validation_exception_handler(
|
|
request: Request, exc: RequestValidationError
|
|
) -> JSONResponse:
|
|
return JSONResponse(
|
|
status_code=422,
|
|
content={"detail": jsonable_encoder(exc.errors())},
|
|
)
|
|
|
|
|
|
async def websocket_request_validation_exception_handler(
|
|
websocket: WebSocket, exc: WebSocketRequestValidationError
|
|
) -> None:
|
|
await websocket.close(
|
|
code=WS_1008_POLICY_VIOLATION, reason=jsonable_encoder(exc.errors())
|
|
)
|