diff sat/plugins/plugin_xep_0060.py @ 3899:1e64f1ed3ebd

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
author Goffi <goffi@goffi.org>
date Wed, 21 Sep 2022 22:32:36 +0200
parents c3e6c54660da
children 8289ac1b34f4
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py	Wed Sep 21 22:29:54 2022 +0200
+++ b/sat/plugins/plugin_xep_0060.py	Wed Sep 21 22:32:36 2022 +0200
@@ -1207,10 +1207,16 @@
         )
         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):