@@ -10,12 +10,12 @@ export default async function fetchPythPrices(priceFeedIds: string[], assets: As
1010 const pricesUrl = new URL ( `${ pythEndpoints . api } /latest_price_feeds` )
1111 const fallbackUrl = new URL ( `${ pythEndpoints . fallbackApi } /latest_price_feeds` )
1212
13- try {
14- priceFeedIds . forEach ( ( id ) => {
15- pricesUrl . searchParams . append ( 'ids[]' , id )
16- fallbackUrl . searchParams . append ( 'ids[]' , id )
17- } )
13+ priceFeedIds . forEach ( ( id ) => {
14+ pricesUrl . searchParams . append ( 'ids[]' , id )
15+ fallbackUrl . searchParams . append ( 'ids[]' , id )
16+ } )
1817
18+ try {
1919 const pythResponse : PythPriceData [ ] = await cacheFn (
2020 async ( ) => {
2121 try {
@@ -24,11 +24,18 @@ export default async function fetchPythPrices(priceFeedIds: string[], assets: As
2424 )
2525 } catch ( error ) {
2626 console . warn ( 'Primary Pyth API failed, falling back to fallback API' , error )
27+ }
2728
29+ try {
2830 return await fetchWithTimeout ( fallbackUrl . toString ( ) , FETCH_TIMEOUT ) . then ( ( res ) =>
2931 res . json ( ) ,
3032 )
33+ } catch ( error ) {
34+ console . error ( 'Fallback Pyth API also failed' , error )
35+ setApiError ( fallbackUrl . toString ( ) , error )
3136 }
37+
38+ return [ ] as PythPriceData [ ]
3239 } ,
3340 pythPriceCache ,
3441 `pythPrices/${ priceFeedIds . flat ( ) . join ( '-' ) } ` ,
@@ -49,6 +56,6 @@ export default async function fetchPythPrices(priceFeedIds: string[], assets: As
4956 return mappedPriceData
5057 } catch ( ex ) {
5158 setApiError ( pricesUrl . toString ( ) , ex )
52- throw ex
59+ return [ ]
5360 }
5461}
0 commit comments