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 better exception handling for errors thrown by the websocket-clie… #155

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion engineio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _connect_websocket(self, url, headers, engineio_path):
ws = websocket.create_connection(
websocket_url + self._get_url_timestamp(), header=headers,
cookie=cookies)
except (ConnectionError, IOError):
except (ConnectionError, IOError, websocket.WebSocketException):
if upgrade:
self.logger.warning(
'WebSocket upgrade failed: connection error')
Expand Down
12 changes: 12 additions & 0 deletions tests/common/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,18 @@ def test_websocket_connection_failed(self, create_connection, _time):
'ws://foo/engine.io/?transport=websocket&EIO=3&t=123.456',
header={'Foo': 'Bar'}, cookie=None)

@mock.patch('engineio.client.time.time', return_value=123.456)
@mock.patch('engineio.client.websocket.create_connection',
side_effect=[websocket.WebSocketException])
def test_websocket_connection_failed_with_websocket_error(
self, create_connection, _time):
c = client.Client()
self.assertRaises(exceptions.ConnectionError, c.connect, 'http://foo',
transports=['websocket'], headers={'Foo': 'Bar'})
create_connection.assert_called_once_with(
'ws://foo/engine.io/?transport=websocket&EIO=3&t=123.456',
header={'Foo': 'Bar'}, cookie=None)

@mock.patch('engineio.client.time.time', return_value=123.456)
@mock.patch('engineio.client.websocket.create_connection',
side_effect=[ConnectionError])
Expand Down