From a7315b74640a724b5d9ca4fb2da5e3b315dee691 Mon Sep 17 00:00:00 2001 From: ygd58 Date: Wed, 1 Jul 2026 06:29:43 +0200 Subject: [PATCH] fix: handle rate limit (429) and timeout errors in fetchJson - Add explicit 429 handling with a clear user-facing message instead of leaking raw HTTP error text when CoinGecko rate-limits the client - Catch AbortError separately so timeout failures surface a descriptive message rather than a generic network error --- tool/market-tool.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tool/market-tool.ts b/tool/market-tool.ts index 7300978..c3e7a68 100644 --- a/tool/market-tool.ts +++ b/tool/market-tool.ts @@ -40,6 +40,11 @@ async function fetchJson( if (!res.ok) { const text = await res.text().catch(() => ""); + if (res.status === 429) { + throw new Error( + "CoinGecko rate limit reached. Please wait a moment before retrying." + ); + } throw new Error( `Market data request failed (${res.status} ${res.statusText})${ text ? `: ${text}` : "" @@ -48,6 +53,11 @@ async function fetchJson( } return (await res.json()) as T; + } catch (err) { + if (err instanceof Error && err.name === "AbortError") { + throw new Error(`Market data request timed out after ${timeoutMs}ms`); + } + throw err; } finally { clearTimeout(timeout); }