Skip to content

Commit

Permalink
Fix #37 - exceptions thrown in AJAX request handler are swallowed
Browse files Browse the repository at this point in the history
The success/fail handlers for ajax.request were being called in a
try/catch statement, causing exceptions to be swallowed when thrown
from within a handler.
  • Loading branch information
Cameron Lakenen committed May 27, 2014
1 parent 1e3d436 commit e65e3f2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/js/utilities/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Crocodoc.addUtility('ajax', function (framework) {
} else if (req) {
req.open(method, url, true);
req.onreadystatechange = function () {
var status;
if (req.readyState === 4) { // DONE
// remove the onreadystatechange handler,
// because it could be called again
Expand All @@ -129,14 +130,17 @@ Crocodoc.addUtility('ajax', function (framework) {
req.onreadystatechange = function () {};

try {
if (req.status === 200) {
ajaxSuccess();
} else {
ajaxFail();
}
status = req.status;
} catch (e) {
// NOTE: IE (9?) throws an error when the request is aborted
ajaxFail();
return;
}

if (status === 200) {
ajaxSuccess();
} else {
ajaxFail();
}
}
};
Expand Down

0 comments on commit e65e3f2

Please sign in to comment.