Skip to content

Commit 9346c40

Browse files
committed
Update websocket.py
Add more error handling
1 parent 11e9d9e commit 9346c40

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pyhilo/websocket.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ async def async_connect(self) -> None:
273273
if self.connected:
274274
LOG.debug("Websocket: async_connect() called but already connected")
275275
return
276+
277+
if self._api.session.closed:
278+
LOG.error("Websocket: Cannot connect, session is closed")
279+
raise CannotConnectError("Session is closed")
276280

277281
LOG.info("Websocket: Connecting to server %s", self._api.endpoint)
278282
if self._api.log_traces:
@@ -344,6 +348,9 @@ async def async_listen(self) -> None:
344348
messages = await self._async_receive_json()
345349
for msg in messages:
346350
self._parse_message(msg)
351+
except asyncio.CancelledError:
352+
LOG.info("Websocket: Listen cancelled.")
353+
raise
347354
except ConnectionClosedError as err:
348355
LOG.error(f"Websocket: Closed while listening: {err}")
349356
LOG.exception(err)

0 commit comments

Comments
 (0)