Skip to content

Commit 4f78e8e

Browse files
committed
fix: update error handling in async_client.py and client.py
1 parent 2ca6dbd commit 4f78e8e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

deepgram/clients/live/v1/async_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,12 @@ async def _signal_exit(self) -> None:
488488
try:
489489
# if the socket connection is closed, the following line might throw an error
490490
await self._socket.send(json.dumps({"type": "CloseStream"}))
491+
except websockets.exceptions.ConnectionClosedOK as e:
492+
self.logger.notice(f"_signal_exit - connection closed: {e.code}")
493+
except websockets.exceptions.WebSocketException as e:
494+
self.logger.error(f"_signal_exit - WebSocketException: {str(e)}")
491495
except Exception as e:
492-
self.logger.error("Exception in AsyncLiveClient._signal_exit, %s", e)
496+
self.logger.error(f"_signal_exit - Exception: {str(e)}")
493497

494498
await asyncio.sleep(0.5)
495499

deepgram/clients/live/v1/client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,15 @@ def _signal_exit(self) -> None:
473473
self.logger.notice("closing socket...")
474474
if self._socket is not None:
475475
self.logger.notice("sending CloseStream...")
476-
self.send(json.dumps({"type": "CloseStream"}))
476+
try:
477+
# if the socket connection is closed, the following line might throw an error
478+
self._socket.send(json.dumps({"type": "CloseStream"}))
479+
except websockets.exceptions.ConnectionClosedOK as e:
480+
self.logger.notice(f"_signal_exit - connection closed: {e.code}")
481+
except websockets.exceptions.WebSocketException as e:
482+
self.logger.error(f"_signal_exit - WebSocketException: {str(e)}")
483+
except Exception as e:
484+
self.logger.error(f"_signal_exit - Exception: {str(e)}")
477485

478486
time.sleep(0.5)
479487

0 commit comments

Comments
 (0)