by printing the whole error body when it cannot be parsed as JSON

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 Utils.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/Utils.js b/Utils.js
index 33c9b77..56b1c9a 100644
--- 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) {
-- 
2.20.1


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to