diff --git a/ably/realtime/connection.py b/ably/realtime/connection.py index d5c79f0d..179e4a6b 100644 --- a/ably/realtime/connection.py +++ b/ably/realtime/connection.py @@ -17,6 +17,11 @@ class ConnectionState(Enum): FAILED = 'failed' +class ProtocolMessageAction(Enum): + CONNECTED = 4 + ERROR = 9 + + class RealtimeConnection: def __init__(self, realtime): self.options = realtime.options @@ -60,13 +65,13 @@ async def ws_read_loop(self): raw = await self.__websocket.recv() msg = json.loads(raw) action = msg['action'] - if action == 4: # CONNECTED + if action == ProtocolMessageAction.CONNECTED: # CONNECTED if self.__connected_future: self.__connected_future.set_result(None) self.__connected_future = None else: - log.warn('CONNECTED message receieved but connected_future not set') - if action == 9: # ERROR + log.warn('CONNECTED message received but connected_future not set') + if action == ProtocolMessageAction.ERROR: # ERROR error = msg["error"] if error['nonfatal'] is False: self.__state = ConnectionState.FAILED diff --git a/ably/realtime/realtime.py b/ably/realtime/realtime.py index 36cf1cbe..de70e41c 100644 --- a/ably/realtime/realtime.py +++ b/ably/realtime/realtime.py @@ -21,7 +21,7 @@ def __init__(self, key=None, **kwargs): if key is not None: options = Options(key=key, **kwargs) else: - raise ValueError("Key is missing. Provide an API key") + raise ValueError("Key is missing. Provide an API key.") self.__auth = Auth(self, options) self.__options = options