Skip to content

Commit 2a74524

Browse files
authored
Merge pull request #1480 from mars-protocol/develop
v2.9.3
2 parents 0ca3c40 + 0264f45 commit 2a74524

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/api/prices/getPythPrices.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)