Skip to content

Commit 5499f04

Browse files
Merge pull request #51 from curvefi/fix/coingecko
fix: catch coingecko errors
2 parents 02c24b0 + 3fbbba3 commit 5499f04

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curvefi/llamalend-api",
3-
"version": "1.0.38",
3+
"version": "1.0.39",
44
"description": "JavaScript library for Curve Lending",
55
"main": "lib/index.js",
66
"author": "Macket",

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)