Skip to content

Commit

Permalink
XHR: Interpret status 0 (usually when server unreachable) as error an…
Browse files Browse the repository at this point in the history
…d actually fire error event.
  • Loading branch information
jayarjo committed Feb 24, 2013
1 parent 27204a1 commit 752174d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
22 changes: 15 additions & 7 deletions bin/js/moxie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3909,7 +3909,7 @@ define("moxie/xhr/XMLHttpRequest", [
_xhr.onreadystatechange = function() {};

// usually status 0 is returned when server is unreachable, but FF also fails to status 0 for 408 timeout
if (_xhr.status === 0 || _xhr.status >= 400) {
if (_xhr.status === 0) {
_error_flag = true;
self.dispatchEvent('error');
} else {
Expand Down Expand Up @@ -3982,12 +3982,16 @@ define("moxie/xhr/XMLHttpRequest", [
} else if (_p('responseType') === 'document') {
_p('responseXML', _p('response'));
}

if (_upload_events_flag) {
self.upload.trigger(e);
}

self.trigger(e);
if (_p('status') > 0) { // status 0 usually means that server is unreachable
if (_upload_events_flag) {
self.upload.trigger(e);
}
self.trigger(e);
} else {
_error_flag = true;
self.dispatchEvent('error');
}
self.trigger('loadend');
});

Expand Down Expand Up @@ -8976,7 +8980,11 @@ define("moxie/runtime/html4/xhr/XMLHttpRequest", [
if ('json' === responseType) {
// strip off <pre>..</pre> tags that might be enclosing the response
if (Basic.typeOf(_response) === 'string') {
return parseJSON(_response.replace(/^\s*<pre[^>]*>/, '').replace(/<\/pre>\s*$/, ''));
try {
return parseJSON(_response.replace(/^\s*<pre[^>]*>/, '').replace(/<\/pre>\s*$/, ''));
} catch (ex) {
return null;
}
}
} else if ('document' === responseType) {

Expand Down
Loading

0 comments on commit 752174d

Please sign in to comment.