]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
api request: add wide spread alert-error logic as smart-on option
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 31 Jan 2023 14:56:25 +0000 (15:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 31 Jan 2023 14:56:27 +0000 (15:56 +0100)
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>
src/Utils.js

index 84d4b56c2f0a60ee9a7b9a6bbe03d30de1fb8fa5..f55b9a5371d3ca8948a5f65b12eabed1515f8554 100644 (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]);