Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak xhr error handling #197

Merged
merged 1 commit into from
Jan 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions browser/lib/transport/xhrrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ var XHRRequest = (function() {
for(var h in headers)
xhr.setRequestHeader(h, headers[h]);

var onerror = xhr.onerror = function(err) {
err.code = 80000;
self.complete(err);
var errorHandler = function(errorEvent, message, code, statusCode) {
var errorMessage = message + ', errorEvent was ' + Utils.inspect(errorEvent) + ', current statusText is ' + self.xhr.statusText;
Logger.logAction(Logger.LOG_ERROR, 'Request.on' + errorEvent.type + '()', errorMessage);
self.complete(new ErrorInfo(errorMessage, code, statusCode));
};
xhr.onabort = function() {
var err = new Error('Request cancelled');
err.statusCode = 400;
onerror(err);
xhr.onerror = function(errorEvent) {
errorHandler(errorEvent, 'XHR error occurred', 80000, 400);
}
xhr.onabort = function(errorEvent) {
errorHandler(errorEvent, 'Request cancelled', 80000, 400);
};
xhr.ontimeout = function() {
var err = new Error('Request timed out');
err.statusCode = 408;
onerror(err);
xhr.ontimeout = function(errorEvent) {
errorHandler(errorEvent, 'Request timed out', 80000, 408);
};

var streaming,
Expand Down Expand Up @@ -294,24 +294,19 @@ var XHRRequest = (function() {
if(body)
if(typeof(body) == 'object') body = JSON.stringify(body);

var onerror = xhr.onerror = function() {
Logger.logAction(Logger.LOG_ERROR, 'Request.onerror()', '');
var err = new Error('Error response');
err.statusCode = 400;
err.code = 80000;
self.complete(err);
var errorHandler = function(errorEvent, message, code, statusCode) {
var errorMessage = message + ', errorEvent was ' + Utils.inspect(errorEvent) + ', current statusText is ' + self.xhr.statusText;
Logger.logAction(Logger.LOG_ERROR, 'Request.on' + errorEvent.type + '()', errorMessage);
self.complete(new ErrorInfo(errorMessage, code, statusCode));
};
xhr.onabort = function() {
Logger.logAction(Logger.LOG_ERROR, 'Request.onabort()', '');
var err = new Error('Request cancelled');
err.statusCode = 400;
onerror(err);
xhr.onerror = function(errorEvent) {
errorHandler(errorEvent, 'XHR error occurred', 80000, 400);
}
xhr.onabort = function(errorEvent) {
errorHandler(errorEvent, 'Request cancelled', 80000, 400);
};
xhr.ontimeout = function() {
Logger.logAction(Logger.LOG_ERROR, 'Request.timeout()', '');
var err = new Error('Request timed out');
err.statusCode = 408;
onerror(err);
xhr.ontimeout = function(errorEvent) {
errorHandler(errorEvent, 'Request timed out', 80000, 408);
};

var streaming,
Expand Down