[pve-devel] [PATCH widget-toolkit] improve error extraction for monStoreErrors
Dominik Csapak
d.csapak at proxmox.com
Tue May 26 11:55:10 CEST 2020
by printing the whole error body when it cannot be parsed as JSON
Signed-off-by: Dominik Csapak <d.csapak at 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
More information about the pve-devel
mailing list