From d90cd8f98454318b77003cecaf3101ae42d1a569 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Tue, 16 Sep 2025 14:49:13 +0000 Subject: [PATCH] fix(fetcher): only retry 503 and 504 --- src/utils/Fetcher.test.ts | 4 ++-- src/utils/Fetcher.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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);