try/except ws receive/send so that reset error doesn't crash the app
This commit is contained in:
1 parent
184abe2cbf
commit
d7446a7692
1 file changed
+6
@@ -247,7 +247,10 @@ class Websocket:
|
||||
ws = self._ws.get_with_default(None)
|
||||
assert ws is not None
|
||||
while True:
|
||||
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)
|
||||
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}")
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user