Skip to content

Commit bfd84b3

Browse files
fix: catch coingecko errors
1 parent 6f65983 commit bfd84b3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,12 @@ export const _getUsdRate = async function (this: Llamalend, assetId: string): Pr
361361
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
362362
`https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
363363
`https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`
364-
const response = await fetch(url);
365-
const data = await response.json() as Record<string, { usd: number }>;
366364
try {
365+
const response = await fetch(url);
366+
const data = await response.json() as Record<string, { usd: number }>;
367367
_usdRatesCache[assetId] = {'rate': data[assetId]['usd'] ?? 0, 'time': Date.now()};
368-
} catch { // TODO pay attention!
368+
} catch {
369+
// coingecko often fails due to 429 (rate limit) errors, due to missing CORS headers we get no details
369370
_usdRatesCache[assetId] = {'rate': 0, 'time': Date.now()};
370371
}
371372
}

0 commit comments

Comments
 (0)