diff --git a/src/utils/Fetcher.test.ts b/src/utils/Fetcher.test.ts index b272ca4..9e52159 100644 --- a/src/utils/Fetcher.test.ts +++ b/src/utils/Fetcher.test.ts @@ -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' } }); } }); diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 2edb1cd..103951b 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -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);