# HG changeset patch # User Goffi # Date 1678966413 -3600 # Node ID 56e5b18f4d06c73e6b55b6fe468d407bdd8e7439 # Parent 1d5a81e3c9e841a7e5296f67d17677b6b1fa671a plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received: this error probably means that the service doesn't support PPS. diff -r 1d5a81e3c9e8 -r 56e5b18f4d06 sat/plugins/plugin_xep_0465.py --- a/sat/plugins/plugin_xep_0465.py Thu Mar 16 12:31:24 2023 +0100 +++ b/sat/plugins/plugin_xep_0465.py Thu Mar 16 12:33:33 2023 +0100 @@ -20,6 +20,7 @@ from twisted.words.protocols.jabber.xmlstream import XMPPHandler from twisted.words.protocols.jabber import jid +from twisted.words.protocols.jabber import error from twisted.words.xish import domish from zope.interface import implementer from wokkel import disco, iwokkel @@ -50,6 +51,10 @@ NS_PPS_SUBSCRIPTIONS = "urn:xmpp:pps:subscriptions:0" NS_PPS_SUBSCRIBERS = "urn:xmpp:pps:subscribers:0" SUBSCRIBERS_NODE_PREFIX = f"{NS_PPS_SUBSCRIBERS}/" +NOT_IMPLEMENTED_MSG = ( + "The service at {service!s} doesn't seem to support Pubsub Public Subscriptions " + "(XEP-0465), please request support from your service administrator." +) class XEP_0465: @@ -139,9 +144,16 @@ """ if service is None: service = client.jid.userhostJID() - items, __ = await self.host.plugins["XEP-0060"].getItems( - client, service, NS_PPS_SUBSCRIPTIONS - ) + try: + items, __ = await self.host.plugins["XEP-0060"].getItems( + client, service, NS_PPS_SUBSCRIPTIONS + ) + except error.StanzaError as e: + if e.condition == "forbidden": + log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) + return [] + else: + raise e ret = [] for item in items: try: @@ -204,9 +216,16 @@ subscribers_node = self.getPublicSubscribersNode(nodeIdentifier) - items, __ = await self.host.plugins["XEP-0060"].getItems( - client, service, subscribers_node - ) + try: + items, __ = await self.host.plugins["XEP-0060"].getItems( + client, service, subscribers_node + ) + except error.StanzaError as e: + if e.condition == "forbidden": + log.warning(NOT_IMPLEMENTED_MSG.format(service=service)) + return {} + else: + raise e ret = {} for item in items: try: