# HG changeset patch # User Goffi # Date 1555222911 -7200 # Node ID cd391ea847cb7305b1a6f33639b83b59d0d13299 # Parent b2f323237fce8d25e7e58463313096cbdb6a2f7d tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback diff -r b2f323237fce -r cd391ea847cb sat/plugins/plugin_xep_0060.py --- a/sat/plugins/plugin_xep_0060.py Sun Apr 14 08:21:51 2019 +0200 +++ b/sat/plugins/plugin_xep_0060.py Sun Apr 14 08:21:51 2019 +0200 @@ -611,6 +611,7 @@ ) # we have no MAM data here, so we add None d.addCallback(lambda data: data + (None,)) + d.addErrback(sat_defer.stanza2NotFound) d.addTimeout(TIMEOUT, reactor) else: # if mam is requested, we have to do a totally different query diff -r b2f323237fce -r cd391ea847cb sat/tools/sat_defer.py --- a/sat/tools/sat_defer.py Sun Apr 14 08:21:51 2019 +0200 +++ b/sat/tools/sat_defer.py Sun Apr 14 08:21:51 2019 +0200 @@ -26,6 +26,7 @@ from twisted.internet import defer from twisted.internet import error as internet_error from twisted.internet import reactor +from twisted.words.protocols.jabber import error as jabber_error from twisted.python import failure from sat.core.constants import Const as C from sat.memory import memory @@ -34,6 +35,14 @@ KEY_NEXT = "next_defer" +def stanza2NotFound(failure_): + """Convert item-not-found StanzaError to exceptions.NotFound""" + failure_.trap(jabber_error.StanzaError) + if failure_.value.condition == u'item-not-found': + raise exceptions.NotFound(failure_.value.text or failure_.value.condition) + return failure_ + + class DelayedDeferred(object): """A Deferred-like which is launched after a delay"""