Mercurial > libervia-backend
diff sat/tools/sat_defer.py @ 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 | 003b8b4b56a7 |
children | ab2696e34d29 |
line wrap: on
line diff
--- 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"""