comparison sat/plugins/plugin_xep_0363.py @ 3399:506fa3d91d3a

plugin XEP-0363: fixed invalid reference to `slot` in catched exception: `slot` was referenced in an exception where it can't exist. This fix avoid a crash and skip the handler when a StanzaError is catched.
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 6505e5cc6ab9
children be6d91572633
comparison
equal deleted inserted replaced
3398:467d6c709f1d 3399:506fa3d91d3a
22 from dataclasses import dataclass 22 from dataclasses import dataclass
23 from urllib import parse 23 from urllib import parse
24 from wokkel import disco, iwokkel 24 from wokkel import disco, iwokkel
25 from zope.interface import implementer 25 from zope.interface import implementer
26 from twisted.words.protocols.jabber import jid, xmlstream, error 26 from twisted.words.protocols.jabber import jid, xmlstream, error
27 from twisted.words.xish import domish
28 from twisted.internet import reactor 27 from twisted.internet import reactor
29 from twisted.internet import defer 28 from twisted.internet import defer
30 from twisted.web import client as http_client 29 from twisted.web import client as http_client
31 from twisted.web import http_headers 30 from twisted.web import http_headers
32 from sat.core.i18n import _ 31 from sat.core.i18n import _
373 372
374 for handler in self.handlers: 373 for handler in self.handlers:
375 try: 374 try:
376 slot = handler.callback(client, request) 375 slot = handler.callback(client, request)
377 except error.StanzaError as e: 376 except error.StanzaError as e:
378 log.warning(f"a stanza error has been raised while processing HTTP Upload of request: {e}") 377 log.warning(
378 "a stanza error has been raised while processing HTTP Upload of "
379 f"request: {e}"
380 )
379 if err is None: 381 if err is None:
380 # we keep the first error to return its condition later, 382 # we keep the first error to return its condition later,
381 # if no other callback handle the request 383 # if no other callback handle the request
382 err = e 384 err = e
383 if slot: 385 else:
384 break 386 if slot:
387 break
385 else: 388 else:
386 log.warning( 389 log.warning(
387 _("no service can handle HTTP Upload request: {elt}") 390 _("no service can handle HTTP Upload request: {elt}")
388 .format(elt=iq_elt.toXml())) 391 .format(elt=iq_elt.toXml()))
389 if err is not None: 392 if err is not None: