From 1a6eac4cccf993010c0630c362eab8f97d6e26b3 Mon Sep 17 00:00:00 2001 From: ciandt-crodrigues Date: Tue, 29 Oct 2024 22:26:49 -0300 Subject: [PATCH 1/3] feat(retry-plugin): allow fallback function to receive failed URL --- packages/retry-plugin/__tests__/retry.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/retry-plugin/__tests__/retry.spec.ts b/packages/retry-plugin/__tests__/retry.spec.ts index 126c33459e..f638331527 100644 --- a/packages/retry-plugin/__tests__/retry.spec.ts +++ b/packages/retry-plugin/__tests__/retry.spec.ts @@ -118,6 +118,24 @@ describe('fetchWithRetry', () => { expect(fetch).toHaveBeenLastCalledWith('https://fallback.com', {}); }); + it('should build fallback URL from remote after retries fail', async () => { + mockErrorFetch(); + const retryTimes = 3; + const responsePromise = fetchWithRetry({ + url: 'https://example.com', + retryTimes, + retryDelay: 0, + fallback: (url) => `${url}/fallback`, + }); + vi.advanceTimersByTime(2000 * retryTimes); + + await expect(responsePromise).rejects.toThrow( + 'The request failed three times and has now been abandoned', + ); + expect(fetch).toHaveBeenCalledTimes(5); //first fetch + retryTimes fetch + expect(fetch).toHaveBeenLastCalledWith('https://example.com/fallback', {}); + }); + it('should handle JSON parse error', async () => { const mockFetch = vi.fn().mockResolvedValueOnce({ ok: true, From 2baab508667de7a4d41e10a659b5a6ccb2e37220 Mon Sep 17 00:00:00 2001 From: ciandt-crodrigues Date: Tue, 29 Oct 2024 22:38:06 -0300 Subject: [PATCH 2/3] feat(retry-plugin): update site --- apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx b/apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx index 1be95039b2..e8e16b924e 100644 --- a/apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx +++ b/apps/website-new/docs/en/plugin/plugins/retry-plugin.mdx @@ -96,7 +96,9 @@ type FetchWithRetryOptions = { options?: RequestInit; retryTimes?: number; retryDelay?: number; - fallback?: (() => string) | ((url: string | URL | globalThis.Request) => string); + fallback?: + | (() => string) + | ((url: string | URL | globalThis.Request) => string); } type ScriptWithRetryOptions = { From 04a9e54ab7a689627df29d4c621505d223e0291b Mon Sep 17 00:00:00 2001 From: ciandt-crodrigues Date: Tue, 29 Oct 2024 22:42:53 -0300 Subject: [PATCH 3/3] feat(retry-plugin): adding changeset --- .changeset/orange-goats-hope.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/orange-goats-hope.md diff --git a/.changeset/orange-goats-hope.md b/.changeset/orange-goats-hope.md new file mode 100644 index 0000000000..937c0c5434 --- /dev/null +++ b/.changeset/orange-goats-hope.md @@ -0,0 +1,5 @@ +--- +'@module-federation/retry-plugin': minor +--- + +Allow fallback function to receive the failed URL in order to build the fallback URL.