Mercurial > libervia-backend
changeset 2911:cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Apr 2019 08:21:51 +0200 |
parents | b2f323237fce |
children | a3faf1c86596 |
files | sat/plugins/plugin_xep_0060.py sat/tools/sat_defer.py |
diffstat | 2 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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"""