]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
improve error extraction for monStoreErrors
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 26 May 2020 09:55:10 +0000 (11:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 26 May 2020 17:04:54 +0000 (19:04 +0200)
by printing the whole error body when it cannot be parsed as JSON

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Utils.js

index 33c9b777349b7dde0f6fd542a319d04502beec46..56b1c9a6aeb91d093a2958f752898c5e99fc2ffe 100644 (file)
--- a/Utils.js
+++ b/Utils.js
@@ -244,17 +244,22 @@ Ext.define('Proxmox.Utils', { utilities: {
        if (!err.statusText) {
            return gettext('Connection error');
        }
-       let msg = `${err.statusText} (${err.status})`;
+       let msg = [`${err.statusText} (${err.status})`];
        if (err.response && err.response.responseText) {
            let txt = err.response.responseText;
            try {
                let res = JSON.parse(txt)
-               for (let [key, value] of Object.entries(res.errors)) {
-                   msg += `<br>${key}: ${value}`;
+               if (res.errors && typeof res.errors === 'object') {
+                   for (let [key, value] of Object.entries(res.errors)) {
+                       msg.push(Ext.String.htmlEncode(`${key}: ${value}`));
+                   }
                }
-           } catch (e) { /* TODO? */ }
+           } catch (e) {
+               // fallback to string
+               msg.push(Ext.String.htmlEncode(txt));
+           }
        }
-       return msg;
+       return msg.join('<br>');
     },
 
     monStoreErrors: function(me, store, clearMaskBeforeLoad) {