From 064707ac23655e8a61afd721e30a933d19e985d1 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 24 Jan 2020 21:19:58 +0100 Subject: [PATCH] Add error handling for when the listener has been logged out --- fbchat/_mqtt.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fbchat/_mqtt.py b/fbchat/_mqtt.py index 9bb361a..b8daa77 100644 --- a/fbchat/_mqtt.py +++ b/fbchat/_mqtt.py @@ -130,11 +130,10 @@ class Mqtt(object): log.debug("Fetching MQTT sequence ID") # Same request as in `Client.fetchThreadList` (j,) = state._graphql_requests(_graphql.from_doc_id("1349387578499440", params)) - try: - return int(j["viewer"]["message_threads"]["sync_sequence_id"]) - except (KeyError, ValueError): - # TODO: Proper exceptions - raise + sequence_id = j["viewer"]["message_threads"]["sync_sequence_id"] + if not sequence_id: + raise _exception.FBchatNotLoggedIn("Failed fetching sequence id") + return int(sequence_id) def _on_connect_handler(self, client, userdata, flags, rc): if rc == 21: @@ -287,6 +286,8 @@ class Mqtt(object): # 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.FBchatNotLoggedIn("MQTT connection refused") else: err = paho.mqtt.client.error_string(rc) log.error("MQTT Error: %s", err)