Skip to content
Snippets Groups Projects
Commit 1e40d901 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1606362 by nod_, Angry Dan, seutje: Use throw when an ajax error occurs...

Issue #1606362 by nod_, Angry Dan, seutje: Use throw when an ajax error occurs and extend JavaScript's Error object.
parent 0be98498
No related branches found
No related tags found
No related merge requests found
......@@ -490,7 +490,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();
......@@ -507,6 +506,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);
};
/**
......
......@@ -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);
......
......@@ -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');
......
......@@ -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);
}
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment