File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
packages/retry-plugin/src Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @module-federation/retry-plugin ' : patch
3+ ---
4+
5+ fix(retry-plugin): add autoParseResponse to auto-select JSON or text based on file extension
Original file line number Diff line number Diff line change @@ -9,6 +9,18 @@ import {
99import logger from './logger' ;
1010import { getRetryUrl , combineUrlDomainWithPathQuery } from './utils' ;
1111
12+ function autoParseResponse ( url : string , response : Response ) {
13+ try {
14+ const parsed = new URL ( url ) ;
15+ if ( parsed . pathname . endsWith ( '.js' ) ) {
16+ return response . text ( ) ;
17+ }
18+ return response . json ( ) ;
19+ } catch ( error ) {
20+ return response . json ( ) ;
21+ }
22+ }
23+
1224async function fetchRetry (
1325 params : FetchRetryOptions ,
1426 lastRequestUrl ?: string ,
@@ -63,7 +75,7 @@ async function fetchRetry(
6375 `${ PLUGIN_IDENTIFIER } : Request failed: ${ response . status } ${ response . statusText || '' } | url: ${ requestUrl } ` ,
6476 ) ;
6577 }
66- await responseClone . json ( ) . catch ( ( error ) => {
78+ await autoParseResponse ( requestUrl , responseClone ) . catch ( ( error ) => {
6779 throw new Error (
6880 `${ PLUGIN_IDENTIFIER } : JSON parse failed: ${ ( error as Error ) ?. message || String ( error ) } | url: ${ requestUrl } ` ,
6981 ) ;
You can’t perform that action at this time.
0 commit comments