File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
src/app/lib/idcta/fetchIdctaConfig Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,19 @@ const cache = new LRUCache<string, IdctaConfig>({
2222async function fetchIdctaConfig ( ) : Promise < IdctaConfig | null > {
2323 const idctaConfigUrl = getIdctaConfigUrl ( ) ;
2424
25+ if ( ! idctaConfigUrl ) return null ;
26+
2527 const cachedConfig = cache . get ( idctaConfigUrl ) ;
2628 if ( cachedConfig ) {
2729 return cachedConfig ;
2830 }
2931
32+ const controller = new AbortController ( ) ;
33+ const timeoutMs = 2000 ;
34+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
35+
3036 try {
31- const response = await fetch ( idctaConfigUrl ) ;
37+ const response = await fetch ( idctaConfigUrl , { signal : controller . signal } ) ;
3238
3339 if ( ! response . ok ) {
3440 throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` ) ;
@@ -37,14 +43,15 @@ async function fetchIdctaConfig(): Promise<IdctaConfig | null> {
3743 const config = await response . json ( ) ;
3844
3945 cache . set ( idctaConfigUrl , config ) ;
40-
4146 return config ;
4247 } catch ( error ) {
4348 logger . error ( IDCTA_FETCH_ERROR , {
4449 url : idctaConfigUrl ,
4550 error,
4651 } ) ;
4752 return null ;
53+ } finally {
54+ clearTimeout ( timeoutId ) ;
4855 }
4956}
5057
You can’t perform that action at this time.
0 commit comments