From 319d450bec6d0ad66f3059fbbf863b3fae856db5 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 31 Jan 2023 15:56:25 +0100 Subject: [PATCH] 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 --- src/Utils.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Utils.js b/src/Utils.js index 84d4b56..f55b9a5 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -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]); -- 2.39.5