diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 45a5bac..1d9dec9 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -484,7 +484,6 @@ Drupal.ajax.prototype.getEffect = function (response) { * Handler for the form redirection error. */ Drupal.ajax.prototype.error = function (response, uri) { - window.alert(Drupal.ajaxError(response, uri)); // Remove the progress element. if (this.progress.element) { $(this.progress.element).remove(); @@ -501,6 +500,7 @@ Drupal.ajax.prototype.error = function (response, uri) { var settings = response.settings || this.settings || Drupal.settings; Drupal.attachBehaviors(this.form, settings); } + throw new Drupal.AjaxError(response, uri); }; /** diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index 3be76c7..fa74a75 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -316,7 +316,7 @@ Drupal.ACDB.prototype.search = function (searchString) { } }, error: function (xmlhttp) { - alert(Drupal.ajaxError(xmlhttp, db.uri)); + throw new Drupal.AjaxError(xmlhttp, db.uri); } }); }, this.delay); diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 627e264..0e3eb11 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -393,9 +393,10 @@ Drupal.getSelection = function (element) { }; /** - * Build an error message from an Ajax response. + * Extends Error to provide handling for Errors in AJAX */ -Drupal.ajaxError = function (xmlhttp, uri) { +Drupal.AjaxError = function(xmlhttp, uri) { + var statusCode, statusText, pathText, responseText, readyStateText, message; if (xmlhttp.status) { statusCode = "\n" + Drupal.t("An AJAX HTTP error occurred.") + "\n" + Drupal.t("HTTP Result Code: !status", {'!status': xmlhttp.status}); @@ -428,10 +429,13 @@ Drupal.ajaxError = function (xmlhttp, uri) { // We don't need readyState except for status == 0. readyStateText = xmlhttp.status === 0 ? ("\n" + Drupal.t("ReadyState: !readyState", {'!readyState': xmlhttp.readyState})) : ""; - message = statusCode + pathText + statusText + responseText + readyStateText; - return message; + this.message = statusCode + pathText + statusText + responseText + readyStateText; + this.name = 'AjaxError'; }; +Drupal.AjaxError.prototype = new Error(); +Drupal.AjaxError.prototype.constructor = Drupal.AjaxError; + // Class indicating that JS is enabled; used for styling purpose. $('html').addClass('js'); diff --git a/core/misc/progress.js b/core/misc/progress.js index 5959f6d..e4c5110 100644 --- a/core/misc/progress.js +++ b/core/misc/progress.js @@ -88,7 +88,7 @@ $.extend(Drupal.ProgressBar.prototype, { pb.timer = setTimeout(function () { pb.sendPing(); }, pb.delay); }, error: function (xmlhttp) { - pb.displayError(Drupal.ajaxError(xmlhttp, pb.uri)); + throw new Drupal.AjaxError(xmlhttp, pb.uri); } }); }