Mercurial > libervia-backend
changeset 4008:56e5b18f4d06
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Mar 2023 12:33:33 +0100 |
parents | 1d5a81e3c9e8 |
children | 48e8b3dba793 |
files | sat/plugins/plugin_xep_0465.py |
diffstat | 1 files changed, 25 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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: