Skip to content

Commit

Permalink
Allow crossDomain errors to be retried (ladjs#1194)
Browse files Browse the repository at this point in the history
When using the retry() functionality on a bad connection, the browser can sometimes fail during a CORS OPTIONS request, which currently doesn't get retried. Superagent throws an error with crossDomain: true property in this case. We should retry instead, since the next attempt might succeed.
  • Loading branch information
tt-mikeolson committed Mar 18, 2017
1 parent 99db1d4 commit d428a34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/should-retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = function shouldRetry(err, res) {
if (res && res.status && res.status >= 500) return true;
// Superagent timeout
if (err && 'timeout' in err && err.code == 'ECONNABORTED') return true;
if (err && 'crossDomain' in err) return true;
return false;
};
};
16 changes: 16 additions & 0 deletions test/client/xdomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,21 @@ describe('xdomain', function(){
next();
});
});

it('should handle x-domain failure after repeat attempts', function(next){
request
.get('//tunne127.com')
.retry(2)
.end(function(err, res){
try {
assert(err, 'error missing');
assert(err.crossDomain, 'not .crossDomain');
assert.equal(2, err.retries, 'expected an error with .retries');
next();
} catch(err) {
next(err);
}
});
});
}
});

0 comments on commit d428a34

Please sign in to comment.