@@ -112,11 +112,16 @@ class AsyncClient(object):
)
async def connect_sock():
- websocket = await websockets.connect(
- uri,
- ping_interval=None,
- open_timeout=self.timeout,
- )
+ try:
+ websocket = await websockets.connect(
+ uri,
+ ping_interval=None,
+ open_timeout=self.timeout,
+ )
+ except asyncio.exceptions.TimeoutError:
+ raise ConnectionError("Timeout while connecting to websocket")
+ except (OSError, websockets.InvalidHandshake, websockets.InvalidURI) as exc:
+ raise ConnectionError(f"Could not connect to websocket: {exc}") from exc
return WebsocketConnection(websocket, self.timeout)
self._connect_sock = connect_sock
The websockets library throws a number of exceptions which are currently not caught leading to unhandled exceptions in the idle loop. Fix this by catching them and reexposing them as a `ConnectionError` which is the exception expected by users of `asyncrpc`. Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de> --- lib/bb/asyncrpc/client.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)