Browse Source

Handle AJAX error responses that come back as HTML

If an AJAX request ends up hitting some sort of error that hasn't been
handled properly in the code yet, it often gets a full HTML page back as
a response, instead of just a text error message. Previously, this would
end up with Intercooler putting the full text of the HTML into the error
element, which is really ugly and confusing.

Now, it will just put an "Unknown error" message, and the actual error
should still end up getting reported to me through Sentry to be able to
investigate.
merge-requests/72/head
Deimos 5 years ago
parent
commit
be8c30a103
  1. 6
      tildes/static/js/scripts.js

6
tildes/static/js/scripts.js

@ -70,6 +70,12 @@ $(function() {
if (xhr.status === 413) {
errorText = "Too much data submitted";
}
// check if the response came back as HTML (unhandled error of some sort)
if (errorText.lastIndexOf("<html>", 500) !== -1) {
errorText = "Unknown error";
}
$statusElement.addClass("form-status-error").text(errorText);
}
$statusElement.fadeIn("slow");

Loading…
Cancel
Save