Buckets:
MisterAI/LocalAI_Demo_backends / cpu-pocket-tts.upgrade-tmp /venv /lib /python3.10 /site-packages /fastapi /exception_handlers.py
| 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()) | |
| ) | |
Xet Storage Details
- Size:
- 1.28 kB
- Xet hash:
- 26b0c2c490843c374885be55517cf6b2ca9c053aa0aecfd1d082cf9aedc49c4a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.