Skip to content

Commit 3b39c64

Browse files
Support Python's ConnectionRefusedError to reject a connection
1 parent 194e1b7 commit 3b39c64

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

docs/server.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ a :class:`socketio.exceptions.ConnectionRefusedError` exception can be raised,
246246
and all of its arguments will be sent to the client with the rejection
247247
message::
248248

249+
from socketio.exceptions import ConnectionRefusedError
250+
249251
@sio.event
250252
def connect(sid, environ, auth):
251253
raise ConnectionRefusedError('authentication failed')

src/socketio/async_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ async def _handle_connect(self, eio_sid, namespace, data):
561561
except exceptions.ConnectionRefusedError as exc:
562562
fail_reason = exc.error_args
563563
success = False
564+
except ConnectionRefusedError as exc:
565+
fail_reason = {"message": "Connection refused by server"}
566+
success = False
564567

565568
if success is False:
566569
if self.always_connect:

src/socketio/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ def _handle_connect(self, eio_sid, namespace, data):
543543
except exceptions.ConnectionRefusedError as exc:
544544
fail_reason = exc.error_args
545545
success = False
546+
except ConnectionRefusedError as exc:
547+
fail_reason = {"message": "Connection refused by server"}
548+
success = False
546549

547550
if success is False:
548551
if self.always_connect:

0 commit comments

Comments
 (0)