Skip to content
Snippets Groups Projects
Commit 6151cbde authored by Angie Byron's avatar Angie Byron
Browse files

#646694 by rfay: Added much more meaningful error reporting to AJAX.

parent f8e75ebd
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -316,18 +316,26 @@ Drupal.getSelection = function (element) { ...@@ -316,18 +316,26 @@ Drupal.getSelection = function (element) {
* Build an error message from an AJAX response. * Build an error message from an AJAX response.
*/ */
Drupal.ajaxError = function (xmlhttp, uri) { Drupal.ajaxError = function (xmlhttp, uri) {
if (xmlhttp.status == 200 || (xmlhttp.status == 500 && xmlhttp.statusText == 'Service unavailable (with message)')) { var statusCode, statusText, pathText, responseText, readyStateText, message;
if ($.trim(xmlhttp.responseText)) { if (xmlhttp.status) {
var message = Drupal.t("An error occurred. \nPath: @uri\nMessage: !text", { '@uri': uri, '!text': xmlhttp.responseText }); statusCode = "\n" + Drupal.t("An AJAX HTTP error occurred.") + "\n" + Drupal.t("HTTP Result Code: !status", {'!status': xmlhttp.status});
}
else {
var message = Drupal.t("An error occurred. \nPath: @uri\n(no information available).", {'@uri': uri });
}
} }
else { else {
var message = Drupal.t("An HTTP error @status occurred. \nPath: @uri", { '@uri': uri, '@status': xmlhttp.status }); statusCode = "\n" + Drupal.t("An AJAX HTTP request terminated abnormally.");
} }
return message.replace(/\n/g, '<br />'); statusCode += "\n" + Drupal.t("Debugging information follows.");
pathText = "\n" + Drupal.t("Path: !uri", {'!uri': uri} );
statusText = xmlhttp.statusText ? ("\n" + Drupal.t("StatusText: !statusText", {'!statusText': $.trim(xmlhttp.statusText)})) : "";
responseText = xmlhttp.responseText ? ("\n" + Drupal.t("ResponseText: !responseText", {'!responseText': $.trim(xmlhttp.responseText)})) : "";
// Make the responseText more readable by stripping HTML tags and newlines.
responseText = responseText.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi,"");
responseText = responseText.replace(/[\n]+\s+/g,"\n");
// 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;
}; };
// Class indicating that JS is enabled; used for styling purpose. // Class indicating that JS is enabled; used for styling purpose.
......
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