Browse Source

AMBARI-2769. FE should show the error-details when it encounters error while persisting web client state. (Andrii Babiichuk via yusaku)

Yusaku Sako 11 years ago
parent
commit
26229f0e97
3 changed files with 34 additions and 23 deletions
  1. 1 1
      ambari-web/app/messages.js
  2. 22 22
      ambari-web/app/models/cluster_states.js
  3. 11 0
      ambari-web/app/utils/ajax.js

+ 1 - 1
ambari-web/app/messages.js

@@ -142,7 +142,7 @@ Em.I18n.translations = {
   'common.process': 'Process',
   'common.property': 'Property',
   'common.installed': 'Installed',
-  'common.persist.error' : 'Error in persisting web client state at ambari server',
+  'common.persist.error' : 'Error in persisting web client state at ambari server:',
   'common.update.error' : 'Error in retrieving web client state from ambari server',
   'common.tags': 'Tags',
   'requestInfo.installComponents':'Install Components',

+ 22 - 22
ambari-web/app/models/cluster_states.js

@@ -104,7 +104,6 @@ App.clusterStatus = Ember.Object.create({
         this.set('localdb', newValue.localdb);
       }
 
-      var url = App.apiPrefix + '/persist/';
       var keyValuePair = {};
       var val = {
         clusterName: this.get('clusterName'),
@@ -114,39 +113,40 @@ App.clusterStatus = Ember.Object.create({
       };
       keyValuePair[this.get('key')] = JSON.stringify(val);
 
-
-      jQuery.ajax({
-        async: false,
-        context: this,
-        type: "POST",
-        url: url,
-        data: JSON.stringify(keyValuePair),
-        beforeSend: function () {
-          console.log('BeforeSend: persistKeyValues', keyValuePair);
-        },
-        error: function () {
-          console.log("ERROR");
-          if(newValue.errorCallBack) {
-            newValue.errorCallBack();
-          } else {
-            this.clusterStatusErrorCallBack();
-          }
+      App.ajax.send({
+        name: 'cluster.state',
+        sender: this,
+        data: {
+            key: keyValuePair,
+            newVal: newValue
         },
-        statusCode: require('data/statusCodes')
+        beforeSend: 'clusterStatusBeforeSend',
+        error: 'clusterStatusErrorCallBack'
       });
       return newValue;
     }
   },
-
-  clusterStatusErrorCallBack: function() {
+  clusterStatusBeforeSend: function (keyValuePair) {
+    console.log('BeforeSend: persistKeyValues', keyValuePair);
+  },
+  clusterStatusErrorCallBack: function(request, ajaxOptions, error, opt) {
+    console.log("ERROR");
+    if(opt.newValue.errorCallBack) {
+      opt.newValue.errorCallBack();
+    } else {
+      var doc = $.parseXML(request.responseText);
+      var msg = 'Error ' + (request.status) + ' ';
+      msg += $(doc).find("body p").text();
+    }
     App.ModalPopup.show({
       header: Em.I18n.t('common.error'),
       secondary: false,
+      response: msg,
       onPrimary: function () {
         this.hide();
       },
       bodyClass: Ember.View.extend({
-        template: Ember.Handlebars.compile('<p>{{t common.persist.error}}</p>')
+        template: Ember.Handlebars.compile('<p>{{t common.persist.error}} {{response}}</p>')
       })
     });
   },

+ 11 - 0
ambari-web/app/utils/ajax.js

@@ -512,6 +512,17 @@ var urls = {
       };
     }
   },
+  'cluster.state': {
+    'type': 'POST',
+    'real': '/persist/',
+    'format': function (data, opt) {
+      return {
+        async: false,
+        data: JSON.stringify(data.key),
+        newValue: data.newVal
+      };
+    }
+  },
   'cluster.update_upgrade_version': {
     'real': '/stacks2/HDP/versions?fields=stackServices/StackServices,Versions',
     'mock': '/data/wizard/stack/stacks.json',