From: Dominik Csapak Date: Tue, 26 May 2020 09:55:10 +0000 (+0200) Subject: improve error extraction for monStoreErrors X-Git-Url: https://git.proxmox.com/?p=proxmox-widget-toolkit.git;a=commitdiff_plain;h=9fcd1bdb427b774f89fd30fd108201d5dce6a013 improve error extraction for monStoreErrors by printing the whole error body when it cannot be parsed as JSON Signed-off-by: Dominik Csapak --- 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 += `
${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('
'); }, monStoreErrors: function(me, store, clearMaskBeforeLoad) {