From 2502e5062ae96466fbf84ec27d58530d670410e1 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 21 Sep 2022 22:32:36 +0200 Subject: [PATCH] plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`: `exceptions.NotFound` is now raised in stead of `item-not-found` `StanzaError` for consistency with `getItems` and because it's easier to catch (condition has to be checked when `StanzaError` is received). rel 372 --- sat/plugins/plugin_xep_0060.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sat/plugins/plugin_xep_0060.py b/sat/plugins/plugin_xep_0060.py index f3822e0c..5e3c66d1 100644 --- a/sat/plugins/plugin_xep_0060.py +++ b/sat/plugins/plugin_xep_0060.py @@ -1207,10 +1207,16 @@ class XEP_0060(object): ) if not cont: return trigger_sub - subscription = await client.pubsub_client.subscribe( - service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options, - sender=client.jid.userhostJID() - ) + try: + subscription = await client.pubsub_client.subscribe( + service, nodeIdentifier, sub_jid or client.jid.userhostJID(), + options=options, sender=client.jid.userhostJID() + ) + except error.StanzaError as e: + if e.condition == 'item-not-found': + raise exceptions.NotFound(e.text or e.condition) + else: + raise e return subscription def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):