Skip to content

Commit

Permalink
Fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett Willemsen committed Mar 23, 2021
1 parent ce08803 commit d61072f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,15 @@ test('API `delete` calls with shorthand `get` should succeed', async done => {
done();
});


test('API catches ETIMEDOUT error', async done => {
nock('https://api.pagerduty.com').get('/incidents').replyWithError({code: 'ETIMEDOUT'})
nock('https://api.pagerduty.com')
.get('/incidents')
.replyWithError({code: 'ETIMEDOUT'});

const pd = api({token: 'someToken1234567890'});

await expect(pd.get('/incidents')).rejects.toThrow('request to https://api.pagerduty.com/incidents failed, reason: undefined');
await expect(pd.get('/incidents')).rejects.toThrow(
'request to https://api.pagerduty.com/incidents failed, reason: undefined'
);
done();
});
32 changes: 17 additions & 15 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@ function fetch_retry(
options: RequestOptions
): Promise<Response> {
return new Promise((resolve, reject) => {
fetch(url, options).then(response => {
// We don't want to `reject` when retries have finished
// Instead simply stop trying and return.
if (retries === 0) return resolve(response);
if (response.status === 429) {
const {retryTimeout = 20000} = options;
retryTimeoutPromise(retryTimeout).then(() => {
fetch_retry(url, retries - 1, options)
.then(resolve)
.catch(reject);
});
} else {
resolve(response);
}
}).catch(reject);
fetch(url, options)
.then(response => {
// We don't want to `reject` when retries have finished
// Instead simply stop trying and return.
if (retries === 0) return resolve(response);
if (response.status === 429) {
const {retryTimeout = 20000} = options;
retryTimeoutPromise(retryTimeout).then(() => {
fetch_retry(url, retries - 1, options)
.then(resolve)
.catch(reject);
});
} else {
resolve(response);
}
})
.catch(reject);
});
}

Expand Down

0 comments on commit d61072f

Please sign in to comment.