diff --git a/fbchat/_exception.py b/fbchat/_exception.py index df99b88..76aa047 100644 --- a/fbchat/_exception.py +++ b/fbchat/_exception.py @@ -90,7 +90,7 @@ class InvalidParameters(ExternalError): class NotLoggedIn(ExternalError): """Raised by Facebook if the client has been logged out.""" - code = attr.ib(1357001) + code = attr.ib() @attr.s(slots=True, auto_exc=True) diff --git a/fbchat/_mqtt.py b/fbchat/_mqtt.py index 762fced..0fddeb7 100644 --- a/fbchat/_mqtt.py +++ b/fbchat/_mqtt.py @@ -168,10 +168,10 @@ class Listener: (j,) = session._graphql_requests( _graphql.from_doc_id("1349387578499440", params) ) - try: - return int(j["viewer"]["message_threads"]["sync_sequence_id"]) - except (KeyError, ValueError) as e: - raise _exception.ParseError("Could not find sequence id", data=j) from e + sequence_id = j["viewer"]["message_threads"]["sync_sequence_id"] + if not sequence_id: + raise _exception.NotLoggedIn("Failed fetching sequence id") + return int(sequence_id) def _on_connect_handler(self, client, userdata, flags, rc): if rc == 21: @@ -321,6 +321,8 @@ class Listener: # This error is wrongly classified # See https://github.com/eclipse/paho.mqtt.python/issues/340 log.warning("Connection error, retrying") + elif rc == paho.mqtt.client.MQTT_ERR_CONN_REFUSED: + raise _exception.NotLoggedIn("MQTT connection refused") else: err = paho.mqtt.client.error_string(rc) log.error("MQTT Error: %s", err)