From e010abcd95e88b4b76326ce2bd8e793506df7fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 23 Mar 2022 16:10:05 +0100 Subject: plugins/contact: Move error handling where the error actually happens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/contact.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/contact.py b/plugins/contact.py index a3a0514b..070fbe4c 100644 --- a/plugins/contact.py +++ b/plugins/contact.py @@ -13,6 +13,7 @@ Usage """ from poezio.plugin import BasePlugin +from slixmpp.exceptions import IqError, IqTimeout from slixmpp.jid import InvalidJID CONTACT_TYPES = ['abuse', 'admin', 'feedback', 'sales', 'security', 'support'] @@ -25,12 +26,6 @@ class Plugin(BasePlugin): help='Get the Contact Addresses of a JID') def on_disco(self, iq): - if iq['type'] == 'error': - error_condition = iq['error']['condition'] - error_text = iq['error']['text'] - message = 'Error getting Contact Addresses from %s: %s: %s' % (iq['from'], error_condition, error_text) - self.api.information(message, 'Error') - return info = iq['disco_info'] contacts = [] # iterate all data forms, in case there are multiple @@ -57,3 +52,9 @@ class Plugin(BasePlugin): self.on_disco(iq) except InvalidJID as e: self.api.information('Invalid JID “%s”: %s' % (jid, e), 'Error') + except (IqError, IqTimeout,) as exn: + ifrom = exn.iq['from'] + condition = exn.iq['error']['condition'] + text = exn.iq['error']['text'] + message = f'Error getting Contact Addresses from {ifrom}: {condition}: {text}' + self.api.information(message, 'Error') -- cgit v1.2.3