# HG changeset patch # User Goffi # Date 1620221853 -7200 # Node ID bbf92ef05f381c5b47a9cd46c702ba49c63154b4 # Parent e84ffb48acd4f94dd824e47dfe1c1ed04b1c1bc4 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 diff -r e84ffb48acd4 -r bbf92ef05f38 sat/plugins/plugin_xep_0166.py --- a/sat/plugins/plugin_xep_0166.py Wed May 05 15:37:33 2021 +0200 +++ b/sat/plugins/plugin_xep_0166.py Wed May 05 15:37:33 2021 +0200 @@ -155,7 +155,7 @@ 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 @@ 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 @@ @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 ## diff -r e84ffb48acd4 -r bbf92ef05f38 sat/plugins/plugin_xep_0234.py --- a/sat/plugins/plugin_xep_0234.py Wed May 05 15:37:33 2021 +0200 +++ b/sat/plugins/plugin_xep_0234.py Wed May 05 15:37:33 2021 +0200 @@ -698,6 +698,8 @@ 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(