monStoreErrors: refactor out and render param exception errors

adapt the .x-mask-msg-text class to center the text, as else this
looks not to nice..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-04-24 16:59:13 +02:00
parent c6cf52f197
commit dca21e597e
2 changed files with 23 additions and 9 deletions

View File

@ -235,6 +235,23 @@ Ext.define('Proxmox.Utils', { utilities: {
}
},
getResponseErrorMessage: (err) => {
if (!err.statusText) {
return gettext('Connection error');
}
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}`;
}
} catch (e) { /* TODO? */ }
}
return msg;
},
monStoreErrors: function(me, store, clearMaskBeforeLoad) {
if (clearMaskBeforeLoad) {
me.mon(store, 'beforeload', function(s, operation, eOpts) {
@ -258,15 +275,8 @@ Ext.define('Proxmox.Utils', { utilities: {
return;
}
var msg;
/*jslint nomen: true */
var operation = request._operation;
var error = operation.getError();
if (error.statusText) {
msg = error.statusText + ' (' + error.status + ')';
} else {
msg = gettext('Connection error');
}
let error = request._operation.getError();
let msg = Proxmox.Utils.getResponseErrorMessage(error);
Proxmox.Utils.setErrorMask(me, msg);
});
},

View File

@ -5,3 +5,7 @@
.pmx-hint {
background-color: LightYellow;
}
.x-mask-msg-text {
text-align: center;
}