diff --git a/adapters/balance/index.ts b/adapters/balance/index.ts index 45fc68b..76b8962 100644 --- a/adapters/balance/index.ts +++ b/adapters/balance/index.ts @@ -13,9 +13,14 @@ export async function latest( timestampDeployed: number, ): Promise { if (!res) { - let r = await fetch(`https://api.llama.fi/emission/${adapter}`).then((r) => - r.json(), - ); + let r; + try { + r = await fetch(`https://api.llama.fi/emission/${adapter}`).then((r) => + r.json(), + ); + } catch { + return timestampDeployed; + } if (!r.body) return timestampDeployed; r = JSON.parse(r.body); return r.metadata.incompleteSections == null || diff --git a/adapters/supply/index.ts b/adapters/supply/index.ts index d958bd4..6b2065f 100644 --- a/adapters/supply/index.ts +++ b/adapters/supply/index.ts @@ -8,9 +8,14 @@ let res: number; export async function latest(key: string, reference: number): Promise { if (!res) { - let r = await fetch(`https://api.llama.fi/emission/${key}`).then((r) => - r.json(), - ); + let r; + try { + r = await fetch(`https://api.llama.fi/emission/${key}`).then((r) => + r.json(), + ); + } catch { + return reference; + } if (!r.body) return reference; r = JSON.parse(r.body); return r.metadata.incompleteSections == null || diff --git a/utils/convertToChartData.ts b/utils/convertToChartData.ts index 1859c05..e2f603e 100644 --- a/utils/convertToChartData.ts +++ b/utils/convertToChartData.ts @@ -111,11 +111,14 @@ async function appendMissingDataSections( const incompleteSections = data.metadata.incompleteSections; if (incompleteSections == null || incompleteSections.length == 0) return; - let res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) => - r.json(), - ); + let res = []; + try { + res = await fetch(`https://api.llama.fi/emission/${protocol}`).then((r) => + r.json(), + ); + } catch {} let body = res.body ? JSON.parse(res.body) : []; - res = body && body.length != 0 ? body.documentedData?.data ?? body.data : []; + res = body && body.length ? body.documentedData?.data ?? body.data : []; if (nullsInApiData(res)) { await sendMessage(