Skip to content

Commit c24647c

Browse files
committed
Improve WebSocket error handling in app.py by adding exception management for connection issues and logging errors. This enhances the robustness of the chat functionality.
1 parent c95cecb commit c24647c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

app.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,15 @@ def ws_v1_chat(ws):
215215
chat.register(ws)
216216

217217
while True:
218-
# Receive message from client
219-
message = ws.receive()
220-
if not message:
218+
# Receive.
219+
try:
220+
message = ws.receive()
221+
if not message:
222+
break
223+
except Exception as e:
224+
if 'ConnectionClosed' in str(type(e)):
225+
break
226+
app.logger.error(f"WebSocket error: {str(e)}", exc_info=True)
221227
break
222228

223229
try:

0 commit comments

Comments
 (0)