Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-cooks-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/retry-plugin': patch
---

fix(retry-plugin): add autoParseResponse to auto-select JSON or text based on file extension
14 changes: 13 additions & 1 deletion packages/retry-plugin/src/fetch-retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import {
import logger from './logger';
import { getRetryUrl, combineUrlDomainWithPathQuery } from './utils';

function autoParseResponse(url: string, response: Response) {
try {
const parsed = new URL(url);
if (parsed.pathname.endsWith('.js')) {
return response.text();
}
return response.json();
} catch (error) {
return response.json();
}
}

async function fetchRetry(
params: FetchRetryOptions,
lastRequestUrl?: string,
Expand Down Expand Up @@ -63,7 +75,7 @@ async function fetchRetry(
`${PLUGIN_IDENTIFIER}: Request failed: ${response.status} ${response.statusText || ''} | url: ${requestUrl}`,
);
}
await responseClone.json().catch((error) => {
await autoParseResponse(requestUrl, responseClone).catch((error) => {
throw new Error(
`${PLUGIN_IDENTIFIER}: JSON parse failed: ${(error as Error)?.message || String(error)} | url: ${requestUrl}`,
);
Expand Down
Loading