Skip to content

Commit 7a2e014

Browse files
committed
chore: improve exception handling for WebSocket message processing
Move exception handling for `decode_raw_websocket_frame` to the calling function Move exception handling for `decode_raw_websocket_frame` to the calling function
1 parent 4d57f96 commit 7a2e014

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ably/transport/websockettransport.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,21 @@ async def ws_read_loop(self):
193193
try:
194194
async for raw in self.websocket:
195195
# Decode based on format
196-
msg = self.decode_raw_websocket_frame(raw)
197-
if msg is not None:
196+
try:
197+
msg = self.decode_raw_websocket_frame(raw)
198198
task = asyncio.create_task(self.on_protocol_message(msg))
199199
task.add_done_callback(self.on_protcol_message_handled)
200+
except Exception as e:
201+
log.exception(
202+
f"WebSocketTransport.decode(): Unexpected exception handling channel message: {e}"
203+
)
200204
except ConnectionClosedOK:
201205
return
202206

203207
def decode_raw_websocket_frame(self, raw: str | bytes) -> dict:
204-
try:
205-
if self.format == 'msgpack':
206-
return msgpack.unpackb(raw)
207-
return json.loads(raw)
208-
except Exception as e:
209-
log.exception(f"WebSocketTransport.decode(): Unexpected exception handing channel message: {e}")
210-
return None
208+
if self.format == 'msgpack':
209+
return msgpack.unpackb(raw)
210+
return json.loads(raw)
211211

212212
def on_protcol_message_handled(self, task):
213213
try:

0 commit comments

Comments
 (0)