plugin XEP-0166, XEP-0234: better management of terminate:
- new `text` argument to specify human readable reason of termination - handling of `FirstError` (used when a error happens in a DeferredList) - handling of `StanzaError` - (XEP-0234): show human readable text of the reason if present
This commit is contained in:
parent
3024ae2be0
commit
8ed9e310c5
2 changed files with 13 additions and 3 deletions
|
|
@ -155,7 +155,7 @@ class XEP_0166(object):
|
|||
def _terminateEb(self, failure_):
|
||||
log.warning(_("Error while terminating session: {msg}").format(msg=failure_))
|
||||
|
||||
def terminate(self, client, reason, session):
|
||||
def terminate(self, client, reason, session, text=None):
|
||||
"""Terminate the session
|
||||
|
||||
send the session-terminate action, and delete the session data
|
||||
|
|
@ -172,6 +172,8 @@ class XEP_0166(object):
|
|||
else:
|
||||
for elt in reason:
|
||||
reason_elt.addChild(elt)
|
||||
if text is not None:
|
||||
reason_elt.addElement("text", content=text)
|
||||
self._delSession(client, session["id"])
|
||||
d = iq_elt.send()
|
||||
d.addErrback(self._terminateEb)
|
||||
|
|
@ -203,11 +205,17 @@ class XEP_0166(object):
|
|||
@param client: %(doc_client)s
|
||||
"""
|
||||
log.warning(f"Error while processing jingle request [{client.profile}]")
|
||||
if isinstance(failure_.value, defer.FirstError):
|
||||
failure_ = failure_.value.subFailure.value
|
||||
if isinstance(failure_, exceptions.DataError):
|
||||
return self.sendError(client, "bad-request", session['id'], request)
|
||||
return self.sendError(client, "bad-request", session["id"], request)
|
||||
elif isinstance(failure_, error.StanzaError):
|
||||
return self.terminate(client, self.REASON_FAILED_APPLICATION, session,
|
||||
text=str(failure_))
|
||||
else:
|
||||
log.error(f"Unmanaged jingle exception: {failure_}")
|
||||
return self.terminate(client, self.REASON_FAILED_APPLICATION, session)
|
||||
return self.terminate(client, self.REASON_FAILED_APPLICATION, session,
|
||||
text=str(failure_))
|
||||
|
||||
## methods used by other plugins ##
|
||||
|
||||
|
|
|
|||
|
|
@ -698,6 +698,8 @@ class XEP_0234:
|
|||
first_child = jingle_elt.firstChildElement()
|
||||
if first_child is not None:
|
||||
reason = first_child.name
|
||||
if jingle_elt.text is not None:
|
||||
reason = f"{reason} - {jingle_elt.text}"
|
||||
else:
|
||||
reason = C.PROGRESS_ERROR_FAILED
|
||||
self.host.bridge.progressError(
|
||||
|
|
|
|||
Loading…
Reference in a new issue