Mercurial > libervia-pubsub
changeset 391:1d2222a91e6b
pubsub_admin: catch errors on publish, and send an iq error
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Feb 2019 18:05:02 +0100 |
parents | fba96e95e329 |
children | 3fb2ff438f09 |
files | src/pubsub_admin.py |
diffstat | 1 files changed, 18 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pubsub_admin.py Fri Feb 15 18:04:05 2019 +0100 +++ b/src/pubsub_admin.py Fri Feb 15 18:05:02 2019 +0100 @@ -24,7 +24,8 @@ from zope.interface import implements from twisted.python import log from twisted.internet import defer -from twisted.words.protocols.jabber import jid, error, xmlstream +from twisted.words.protocols.jabber import jid, error as jabber_error, xmlstream +from sat_pubsub import error from wokkel.subprotocols import XMPPHandler from wokkel import disco, iwokkel, pubsub @@ -43,7 +44,7 @@ self.xmlstream.addObserver(ADMIN_REQUEST, self.onAdminRequest) def sendError(self, iq_elt, condition=u'bad-request'): - stanza_error = error.StanzaError(u'bad-request') + stanza_error = jabber_error.StanzaError(condition) iq_error = stanza_error.toResponse(iq_elt) self.parent.xmlstream.send(iq_error) @@ -101,12 +102,21 @@ # we don't use a DeferredList because we want to be sure that # each request is done in order - payload = yield self.backend.publish( - nodeIdentifier=node, - items=[item], - requestor=requestor, - pep=pep, - recipient=recipient) + try: + payload = yield self.backend.publish( + nodeIdentifier=node, + items=[item], + requestor=requestor, + pep=pep, + recipient=recipient) + except (error.Forbidden, error.ItemForbidden): + __import__('pudb').set_trace() + self.sendError(iq_elt, u"forbidden") + return + except Exception as e: + self.sendError(iq_elt, u"internal-server-error") + log.msg(u"INTERNAL ERROR: {msg}".format(msg=e)) + return result_item_elt = result_publish_elt.addElement(u'item') # either the id was given and it is available in item