From bc1e3edf1728672b2af9ffb9c312992829d13f48 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 5 Jan 2020 20:29:44 +0100 Subject: [PATCH] Small fixes Handle more errors, and fix Client.stopListening --- fbchat/_client.py | 9 ++++++--- fbchat/_mqtt.py | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index 7ab6941..f9fc529 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -2834,10 +2834,13 @@ class Client(object): def stopListening(self): """Stop the listening loop.""" - if not self._mqtt: - raise ValueError("Not listening") - self._mqtt.disconnect() self.listening = False + if not self._mqtt: + return + self._mqtt.disconnect() + # TODO: Preserve the _mqtt object + # Currently, there's some issues when disconnecting + self._mqtt = None def listen(self, markAlive=None): """Initialize and runs the listening loop continually. diff --git a/fbchat/_mqtt.py b/fbchat/_mqtt.py index 0a6070f..8504a3e 100644 --- a/fbchat/_mqtt.py +++ b/fbchat/_mqtt.py @@ -91,6 +91,12 @@ class Mqtt: if "lastIssuedSeqId" in j: self._sequence_id = j["lastIssuedSeqId"] + if "errorCode" in j: + # Known types: ERROR_QUEUE_OVERFLOW | ERROR_QUEUE_NOT_FOUND + # 'F\xfa\x84\x8c\x85\xf8\xbc-\x88 FB_PAGES_INSUFFICIENT_PERMISSION\x00' + log.error("MQTT error code %s received", j["errorCode"]) + # TODO: Consider resetting the sync_token and sequence ID here? + log.debug("MQTT payload: %s", j) # Call the external callback