exception WebsocketDisconnected without code #2434
Unanswered
vessaldaneshvar
asked this question in
Potential Issue
Replies: 2 comments
-
I can't read this. Please post a code snippet I can reproduce the issue. |
Beta Was this translation helpful? Give feedback.
0 replies
-
requirements:
if network connection break without disconnect from client, below exception raised |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Title:
WebSocketDisconnect KeyError on missing 'code' field in disconnect message
Description:
Issue:
When the network connection is accidentally terminated without providing a 'code' field in the disconnect message, the WebSocketDisconnect exception in the starlette library raises a KeyError, resulting in an unhandled exception.
File/Location:
[Include the file path and line number where the issue is occurring. In this case, it's starlette/websockets.py, line 109]
Exception Stack Trace:
site-packages/starlette/websockets.py", line 105, in _raise_on_disconnect
raise WebSocketDisconnect(message["code"], message.get("reason"))
KeyError: 'code'
Expected Behavior:
The WebSocketDisconnect exception should gracefully handle cases where the 'code' field is not present in the disconnect message, avoiding the occurrence of unhandled exceptions.
Steps to Reproduce:
Describe the steps to reproduce the issue, if applicable.
Proposed Solution:
Handle the absence of the 'code' field in the disconnect message by providing a default value or checking for its existence before accessing it. This prevents the KeyError and ensures a smoother error handling process.
Environment (if applicable):
Operating system
Python version
Other relevant details
Labels (if applicable):
bug
error-handling
Priority:
Medium
Additional Information:
Any additional information or context that may help in addressing the issue.
Beta Was this translation helpful? Give feedback.
All reactions