Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSocketRequestCompleted exception for normal WebSocket closures #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/flask_sock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
from simple_websocket import Server, ConnectionClosed


class WebSocketRequestCompleted(Exception):
"""Exception indicating that a WebSocket request has completed normally.

This exception can be used in Flask Sock applications to signify that a
WebSocket request has finished as expected, and should not be treated as an error.

It can be combined with the 'ignore_errors' option in Sentry's initialization
to ensure that such exceptions are not reported as errors in Sentry.
"""
pass


class Sock:
"""Instantiate the Flask-Sock extension.

Expand Down Expand Up @@ -81,7 +93,7 @@ def __call__(self, *args, **kwargs):
WSGI_LOCAL.already_handled = True
return ALREADY_HANDLED
elif ws.mode == 'gunicorn':
raise StopIteration()
raise WebSocketRequestCompleted()
elif ws.mode == 'werkzeug':
return super().__call__(*args, **kwargs)
else:
Expand Down