diff --git a/ably/realtime/connection.py b/ably/realtime/connection.py index 3a154bae..d5c79f0d 100644 --- a/ably/realtime/connection.py +++ b/ably/realtime/connection.py @@ -14,6 +14,7 @@ class ConnectionState(Enum): CONNECTED = 'connected' CLOSING = 'closing' CLOSED = 'closed' + FAILED = 'failed' class RealtimeConnection: @@ -68,6 +69,7 @@ async def ws_read_loop(self): if action == 9: # ERROR error = msg["error"] if error['nonfatal'] is False: + self.__state = ConnectionState.FAILED if self.__connected_future: self.__connected_future.set_exception( AblyAuthException(error["message"], error["statusCode"], error["code"])) diff --git a/test/ably/realtimeconnection_test.py b/test/ably/realtimeconnection_test.py index 134c1f9d..929161a7 100644 --- a/test/ably/realtimeconnection_test.py +++ b/test/ably/realtimeconnection_test.py @@ -39,4 +39,5 @@ async def test_auth_invalid_key(self): ably = await RestSetup.get_ably_realtime(key=self.valid_key_format) with pytest.raises(AblyAuthException): await ably.connect() + assert ably.connection.state == ConnectionState.FAILED await ably.close()