api request: add wide spread alert-error logic as smart-on option

The "smartness" is mostly "enable it automatically if the caller did
not specify an explicit override and there's neither a failure nor
callback function define", but that should cover most cases.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-01-31 15:56:25 +01:00
parent cf93d1da50
commit 319d450bec

View File

@ -418,6 +418,10 @@ utilities: {
waitMsg: gettext('Please wait...'),
}, reqOpts);
// default to enable if user isn't handling the failure already explicitly
let autoErrorAlert = reqOpts.autoErrorAlert ??
(typeof reqOpts.failure !== 'function' && typeof reqOpts.callback !== 'function');
if (!newopts.url.match(/^\/api2/)) {
newopts.url = '/api2/extjs' + newopts.url;
}
@ -439,6 +443,9 @@ utilities: {
response.htmlStatus = Proxmox.Utils.extractRequestError(result, true);
Ext.callback(callbackFn, options.scope, [options, false, response]);
Ext.callback(failureFn, options.scope, [response, options]);
if (autoErrorAlert) {
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
}
return;
}
Ext.callback(callbackFn, options.scope, [options, true, response]);