changeset 1756:061011fad5b1

plugin XEP-0260: better proxy error handling: - display a better message in logs - fixed fallback to IBB
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2015 22:37:56 +0100
parents d2e023da2983
children abd6d6f89006
files src/plugins/plugin_xep_0260.py
diffstat 1 files changed, 19 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0260.py	Thu Dec 17 22:10:53 2015 +0100
+++ b/src/plugins/plugin_xep_0260.py	Thu Dec 17 22:37:56 2015 +0100
@@ -50,7 +50,9 @@
 
 
 class ProxyError(Exception):
-    pass
+
+    def __str__(self):
+        return "an error happened while trying to use the proxy"
 
 
 class XEP_0260(object):
@@ -157,7 +159,8 @@
         iq_elt, transport_elt = self._j.buildAction(self._j.A_TRANSPORT_INFO, session, content_name, profile)
         transport_elt.addElement('proxy-error')
         iq_elt.send()
-        log.warning(u"Can't activate proxy, we need to fallback to IBB")
+        log.warning(u"Can't activate proxy, we need to fallback to IBB: {reason}"
+            .format(reason = stanza_error.value.condition))
         client = self.host.getClient(profile)
         self.doFallback(session, content_name, client)
 
@@ -264,6 +267,19 @@
             if content_data['senders'] == session['role']:
                 # we can now start the file transfer (or start it after proxy activation)
                 d.addCallback(lambda dummy: choosed_candidate.startTransfer(transport_data['session_hash']))
+                d.addErrback(self._startEb, session, content_name, client)
+
+    def _startEb(self, fail, session, content_name, client):
+        """Called when it's not possible to start the transfer
+
+        Will try to fallback to IBB
+        """
+        try:
+            reason = unicode(fail.value)
+        except AttributeError:
+            reason = unicode(fail)
+        log.warning(u"Cant start transfert, we'll try fallback method: {}".format(reason))
+        self.doFallback(session, content_name, client)
 
     def _candidateInfo(self, candidate_elt, session, content_name, transport_data, client):
         """Called when best candidate has been received from peer (or if none is working)
@@ -320,7 +336,7 @@
         if proxy_elt.name == 'activated':
             activation_d.callback(None)
         else:
-            activation_d.errback(ProxyError)
+            activation_d.errback(ProxyError())
 
     @defer.inlineCallbacks
     def jingleHandler(self, action, session, content_name, transport_elt, profile):