fix:issue of exception on websocket closing #256
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found that the general
Exception
being thrown in line 194 gave confusing info.I did some research and found that it's not common to raise an exception for a normal closure of a WebSocket connection with a close code of 1000. A close code of 1000 indicates a normal closure, where the connection is being closed gracefully. Raising an exception for a normal closure might be confusing and goes against the typical use of exceptions to signal errors or exceptional conditions. In the code as it was before, the exception handling seems to be used more for control flow (to exit the listening thread) rather than to handle an error.
So I opted to use
ConnectionClosedOK
which is a specific exception class for handling a normal closure with a close code of 1000. This means the exception will be handled for just this specific acceptable outcome, and the user will see the notice message but not see an error.