diff sat/plugins/plugin_misc_upload.py @ 2863:a97a5c73594d

plugin upload: fixed inversion of title and message body + better error message on failed upload
author Goffi <goffi@goffi.org>
date Wed, 20 Mar 2019 09:08:47 +0100
parents 003b8b4b56a7
children 3cac3d050046
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_upload.py	Wed Mar 20 09:08:47 2019 +0100
+++ b/sat/plugins/plugin_misc_upload.py	Wed Mar 20 09:08:47 2019 +0100
@@ -26,6 +26,7 @@
 from sat.tools import xml_tools
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
+from twisted.words.protocols.jabber import error as jabber_error
 import os
 import os.path
 
@@ -91,11 +92,16 @@
             return {"progress": progress_id}
 
         def uploadEb(fail):
-            msg = unicode(fail)
+            if (isinstance(fail.value, jabber_error.StanzaError)
+                and fail.value.condition == 'not-acceptable'):
+                reason = fail.value.text
+            else:
+                reason = unicode(fail.value)
+            msg = D_(u"Can't upload file: {reason}").format(reason=reason)
             log.warning(msg)
             return {
                 "xmlui": xml_tools.note(
-                    u"Can't upload file", msg, C.XMLUI_DATA_LVL_WARNING
+                    msg, D_(u"Can't upload file"), C.XMLUI_DATA_LVL_WARNING
                 ).toXml()
             }