Updated Branches: refs/heads/trunk a69e026f4 -> e032673e6
AMBARI-3133: Ambari web should display the error message when there is server error. (jaimin) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/e032673e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/e032673e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/e032673e Branch: refs/heads/trunk Commit: e032673e6b2ebbbb93eddc503381abedafb76407 Parents: a69e026 Author: Jaimin Jetly <[email protected]> Authored: Fri Sep 6 12:29:36 2013 -0700 Committer: Jaimin Jetly <[email protected]> Committed: Fri Sep 6 12:29:50 2013 -0700 ---------------------------------------------------------------------- ambari-web/app/styles/application.less | 5 +++ ambari-web/app/utils/ajax.js | 52 ++++++++++++++++++++++++++++- ambari-web/app/utils/http_client.js | 28 ++++++++++------ 3 files changed, 73 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e032673e/ambari-web/app/styles/application.less ---------------------------------------------------------------------- diff --git a/ambari-web/app/styles/application.less b/ambari-web/app/styles/application.less index 7f6f451..d20146f 100644 --- a/ambari-web/app/styles/application.less +++ b/ambari-web/app/styles/application.less @@ -3988,6 +3988,11 @@ ul.inline li { .modal-body { max-height: none; + .api-error { + max-height: 403px; + word-wrap:break-word; + overflow: auto; + } } i.icon-asterisks { http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e032673e/ambari-web/app/utils/ajax.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js index 65bca1d..b2fe390 100644 --- a/ambari-web/app/utils/ajax.js +++ b/ambari-web/app/utils/ajax.js @@ -1098,6 +1098,8 @@ App.ajax = { var opt = {}; opt = formatRequest.call(urls[config.name], params); + opt.context = this; + // object sender should be provided for processing beforeSend, success and error responses opt.beforeSend = function (xhr) { if (config.beforeSend) { @@ -1113,6 +1115,8 @@ App.ajax = { opt.error = function (request, ajaxOptions, error) { if (config.error) { config.sender[config.error](request, ajaxOptions, error, opt); + } else { + this.defaultErrorHandler(request,opt.url,opt.type); } }; opt.complete = function () { @@ -1124,5 +1128,51 @@ App.ajax = { opt.url = 'http://' + $.hostName + opt.url; } return $.ajax(opt); + }, + + // A single instance of App.ModalPopup view + modalPopup: null, + /** + * defaultErrorHandler function is referred from App.ajax.send function and App.HttpClient.defaultErrorHandler function + * @jqXHR {jqXHR Object} + * @url {string} + * @method {String} Http method + */ + defaultErrorHandler: function(jqXHR,url,method) { + method = method || 'GET'; + var self = this; + var api = " received on " + method + " method for API: " + url; + var showMessage = true; + try { + var json = $.parseJSON(jqXHR.responseText); + var message = json.message; + } catch (err) { + } + + if (message === undefined) { + showMessage = false; + } + var statusCode = jqXHR.status + " status code"; + if (jqXHR.status === 500 && !this.modalPopup) { + this.modalPopup = App.ModalPopup.show({ + header: jqXHR.statusText, + secondary: false, + onPrimary: function () { + this.hide(); + self.modalPopup = null; + }, + bodyClass: Ember.View.extend({ + classNames: ['api-error'], + template: Ember.Handlebars.compile(['<span class="text-error">{{view.statusCode}}</span><span>{{view.api}}</span>', + '{{#if view.showMessage}}', + '<br><br><pre><strong>Error message: </strong><span class="text-error">{{view.message}}</span></pre>', + '{{/if}}'].join('\n')), + api: api, + statusCode: statusCode, + message: message, + showMessage: showMessage + }) + }); + } } -} +}; http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/e032673e/ambari-web/app/utils/http_client.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/http_client.js b/ambari-web/app/utils/http_client.js index d6f3215..88d05ec 100644 --- a/ambari-web/app/utils/http_client.js +++ b/ambari-web/app/utils/http_client.js @@ -28,9 +28,14 @@ App.HttpClient = Em.Object.create({ * @param jqXHR * @param textStatus * @param errorThrown + * @url api that invoked this callback function */ - defaultErrorHandler: function (jqXHR, textStatus, errorThrown) { - var json = $.parseJSON(jqXHR.responseText); + defaultErrorHandler: function (jqXHR, textStatus, errorThrown, url) { + try { + var json = $.parseJSON(jqXHR.responseText); + } catch (err) { + } + App.ajax.defaultErrorHandler(jqXHR, url); if (json) { Em.assert("HttpClient:", json); } else { @@ -59,14 +64,14 @@ App.HttpClient = Em.Object.create({ xhr.open('GET', url + (url.indexOf('?') >= 0 ? '&_=' : '?_=') + curTime, true); xhr.send(null); - this.onReady(xhr, "", ajaxOptions, mapper, errorHandler); + this.onReady(xhr, "", ajaxOptions, mapper, errorHandler, url); }, /* This function checks if we get response from server Not using onreadystatechange cuz of possible closure */ - onReady: function (xhr, tm, tmp_val, mapper, errorHandler) { + onReady: function (xhr, tm, tmp_val, mapper, errorHandler, url) { var self = this; clearTimeout(tm); var timeout = setTimeout(function () { @@ -74,12 +79,13 @@ App.HttpClient = Em.Object.create({ if (xhr.status == 200) { try { App.store.commit(); - } catch (err) {} + } catch (err) { + } mapper.map($.parseJSON(xhr.responseText)); tmp_val.complete.call(self); xhr.abort(); } else { - errorHandler(xhr , "error", xhr.statusText); + errorHandler(xhr, "error", xhr.statusText, url); } tmp_val = null; @@ -88,7 +94,7 @@ App.HttpClient = Em.Object.create({ timeout = null; } else { - self.onReady(xhr, timeout, tmp_val, mapper, errorHandler); + self.onReady(xhr, timeout, tmp_val, mapper, errorHandler, url); } }, 10); }, @@ -108,10 +114,10 @@ App.HttpClient = Em.Object.create({ var client = this; var request = function () { client.request(url, data, mapper, errorHandler); - url=null; - data=null; - mapper=null; - errorHandler=null; + url = null; + data = null; + mapper = null; + errorHandler = null; } interval = "" + interval;
