fix(fetcher): only retry 503 and 504
This commit is contained in:
parent
c10ca29fda
commit
d90cd8f984
2 changed files with 4 additions and 4 deletions
|
|
@ -216,14 +216,14 @@ describe('fetch', () => {
|
|||
|
||||
test('passes through other error as HttpError after retrying 3 times', async () => {
|
||||
const mockPool = mockAgent.get('https://some-error-url.test');
|
||||
mockPool.intercept({ path: '/' }).reply(500, undefined, { headers: { 'x-foo': 'bar' } }).times(4);
|
||||
mockPool.intercept({ path: '/' }).reply(503, undefined, { headers: { 'x-foo': 'bar' } }).times(4);
|
||||
|
||||
try {
|
||||
await fetcher.text(ctx, new URL('https://some-error-url.test/'));
|
||||
fail();
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(HttpError);
|
||||
expect(error).toMatchObject({ status: 500, headers: { 'x-foo': 'bar' } });
|
||||
expect(error).toMatchObject({ status: 503, headers: { 'x-foo': 'bar' } });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -316,8 +316,8 @@ export class Fetcher {
|
|||
}
|
||||
}
|
||||
|
||||
if (response.status >= 500 && tryCount < 3) {
|
||||
this.logger.warn(`Retrying fetch ${init?.method ?? 'GET'} ${url} because of error`, ctx);
|
||||
if ([503, 504].includes(response.status) && tryCount < 3) {
|
||||
this.logger.warn(`Retrying fetch ${init?.method ?? 'GET'} ${url} because of a temporary server error`, ctx);
|
||||
await this.sleep(333);
|
||||
|
||||
return await this.fetchWithTimeout(ctx, url, init, ++tryCount);
|
||||
|
|
|
|||
Loading…
Reference in a new issue