try/except ws receive/send so that reset error doesn't crash the app

This commit is contained in:
fireph authored and DevilXD committed 2026-05-29 16:20:08 +02:00
1 parent 184abe2cbf
commit d7446a7692
1 file changed
+8 -2
+8 -2
View File
@@ -247,7 +247,10 @@ class Websocket:
ws = self._ws.get_with_default(None)
assert ws is not None
while True:
raw_message: aiohttp.WSMessage = await ws.receive(timeout=timeout)
try:
raw_message: aiohttp.WSMessage = await ws.receive(timeout=timeout)
except aiohttp.ClientConnectionResetError:
raise WebsocketClosed(received=False)
ws_logger.debug(f"Websocket[{self._idx}] received: {raw_message}")
if raw_message.type is WSMsgType.TEXT:
message: JsonType = json.loads(raw_message.data)
@@ -323,7 +326,10 @@ class Websocket:
assert ws is not None
if message["type"] != "PING":
message["nonce"] = create_nonce(CHARS_ASCII, 30)
await ws.send_json(message, dumps=json_minify)
try:
await ws.send_json(message, dumps=json_minify)
except aiohttp.ClientConnectionResetError:
raise WebsocketClosed(received=False)
ws_logger.debug(f"Websocket[{self._idx}] sent: {message}")