Skip to content

Commit

Permalink
fix: ensure node retries happen when using .then syntax (#1487) (#1543)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlene Tshitoka committed Jun 28, 2020
1 parent afd20c1 commit 77bcb11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/request-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ RequestBase.prototype.then = function(resolve, reject) {

this._fullfilledPromise = new Promise((resolve, reject) => {
self.on('abort', () => {
if (this._maxRetries && this._maxRetries > this._retries) {
return;
}

if (this.timedout && this.timedoutError) {
reject(this.timedoutError);
return;
Expand Down
20 changes: 20 additions & 0 deletions test/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,26 @@ describe('.retry(count)', function() {
});
});

it('should handle successful request after repeat attempt from server timeout when using .then(fulfill, reject)', done => {
const url = `/delay/1200/ok/${uniqid()}?built=in`;
request
.get(base + url)
.query('string=ified')
.query({ json: 'ed' })
.timeout(600)
.retry(1)
.then((res, err) => {
try {
assert.ifError(err);
assert(res.ok, 'response should be ok');
assert.equal(res.text, `ok = ${url}&string=ified&json=ed`);
done();
} catch (err_) {
done(err_);
}
});
});

it('should correctly abort a retry attempt', done => {
let aborted = false;
const req = request
Expand Down

0 comments on commit 77bcb11

Please sign in to comment.