fix(realtime): remove empty exception handlers

This commit is contained in:
jibanez-staticduo 2026-09-18 20:42:12 +02:00
parent e0726859ef
commit 16a19f16c2
No known key found for this signature in database
2 changed files with 7 additions and 5 deletions

View file

@ -230,12 +230,14 @@ MAX_REALTIME_OFFER_BYTES: Final = 8 * 1024 * 1024
async def _cache_bounded_offer_body(request: Request) -> None:
content_length: int | None
try:
if int(request.headers.get("content-length", "")) > MAX_REALTIME_OFFER_BYTES:
raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit")
content_length = int(request.headers.get("content-length", ""))
except ValueError:
# A missing or non-numeric content length is checked while streaming below.
pass
content_length = None
if content_length is not None and content_length > MAX_REALTIME_OFFER_BYTES:
raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit")
if hasattr(request, "_body"):
if len(request._body) > MAX_REALTIME_OFFER_BYTES: # pyright: ignore[reportPrivateUsage] # validate Starlette's cached body without consuming it again
raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit")

View file

@ -1522,13 +1522,13 @@ async def websocket_live_session(websocket: WebSocket, session_id: str | None =
await websocket.close(code=1008, reason="Live session rejected")
except RuntimeError:
# The peer may have closed the socket before the rejection response.
pass
return
except Exception:
try:
await websocket.close(code=1011, reason="Live upstream connection failed")
except RuntimeError:
# The peer may have closed the socket before the failure response.
pass
return
finally:
if state.connection is not None:
await state.connection.close()