From cf818f2161579c496bd409f8ed71a09b66440be7 Mon Sep 17 00:00:00 2001 From: Kevin Peters Date: Mon, 10 Nov 2025 16:36:47 -0600 Subject: [PATCH] fix: handle coingecko 404 responses gracefully --- src/utils/coingecko.ts | 59 ++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/utils/coingecko.ts b/src/utils/coingecko.ts index dcbd4c11d..7bb2ef41c 100644 --- a/src/utils/coingecko.ts +++ b/src/utils/coingecko.ts @@ -82,7 +82,15 @@ const coingeckoRequest = async ( signal: params?.abort?.signal, headers, }) - .then((resp) => resp.json()) + .then((resp) => { + if (!resp.ok) { + console.error( + `Coingecko request failed with status ${resp.status}: ${path}`, + ); + return null; + } + return resp.json(); + }) .catch((err) => { console.error('Error fetching from Coingecko', err); return null; @@ -136,7 +144,13 @@ export const fetchTokenPrices = async ( params, ) .then((data) => { - if (data['error'] !== undefined || data['error_code'] !== undefined) { + if (data === null) { + // Request failed (e.g., 404, network error) + resolve([]); + } else if ( + data['error'] !== undefined || + data['error_code'] !== undefined + ) { reject(data['error']); } else { resolve( @@ -186,24 +200,29 @@ export const fetchTokenPrices = async ( `/api/v3/simple/price?ids=${ids.join(',')}&vs_currencies=usd`, params, ) - .then((data) => - resolve( - nativeTokens - .map((tokenId) => { - const cgid = NATIVE_TOKEN_IDS[tokenId.chain]; - if (cgid) { - const { usd } = data[cgid]; - return { - tokenId, - price: usd, - }; - } else { - return null; - } - }) - .filter((v) => !!v), - ), - ) + .then((data) => { + if (data === null) { + // Request failed (e.g., 404, network error) + resolve([]); + } else { + resolve( + nativeTokens + .map((tokenId) => { + const cgid = NATIVE_TOKEN_IDS[tokenId.chain]; + if (cgid) { + const { usd } = data[cgid]; + return { + tokenId, + price: usd, + }; + } else { + return null; + } + }) + .filter((v) => !!v), + ); + } + }) .catch(reject); }), );