]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
utils: improve indentation and better check API result
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 26 Aug 2020 18:02:35 +0000 (20:02 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 26 Aug 2020 18:20:41 +0000 (20:20 +0200)
to avoid dereferencing a null/undefined value.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Utils.js

index 4be95b2be1de56409207a47be7315a40a360c2d1..29cb317027fed253f8df8fe65a57629ca3d53548 100644 (file)
@@ -449,32 +449,35 @@ utilities: {
     },
 
     checked_command: function(orig_cmd) {
-       Proxmox.Utils.API2Request({
-           url: '/nodes/localhost/subscription',
-           method: 'GET',
-           failure: function(response, opts) {
-               Ext.Msg.alert(gettext('Error'), response.htmlStatus);
-           },
-           success: function(response, opts) {
-               let data = response.result.data;
-               if (data.status !== 'Active') {
-                   Ext.Msg.show({
-                       title: gettext('No valid subscription'),
-                       icon: Ext.Msg.WARNING,
-                       message: Proxmox.Utils.getNoSubKeyHtml(data.url),
-                       buttons: Ext.Msg.OK,
-                       callback: function(btn) {
-                           if (btn !== 'ok') {
-                               return;
-                           }
-                           orig_cmd();
-                       },
-                   });
-               } else {
-                   orig_cmd();
-               }
+       Proxmox.Utils.API2Request(
+           {
+               url: '/nodes/localhost/subscription',
+               method: 'GET',
+               failure: function(response, opts) {
+                   Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+               },
+               success: function(response, opts) {
+                   let res = response.result;
+                   if (res === null || res === undefined || !res || res
+                       .data.status !== 'Active') {
+                       Ext.Msg.show({
+                           title: gettext('No valid subscription'),
+                           icon: Ext.Msg.WARNING,
+                           message: Proxmox.Utils.getNoSubKeyHtml(res.data.url),
+                           buttons: Ext.Msg.OK,
+                           callback: function(btn) {
+                               if (btn !== 'ok') {
+                                   return;
+                               }
+                               orig_cmd();
+                           },
+                       });
+                   } else {
+                       orig_cmd();
+                   }
+               },
            },
-       });
+       );
     },
 
     assemble_field_data: function(values, data) {