jackwener/OpenCLI · error · CommandExecutionError

coingecko coin failed: HTTP ${resp.status}

Error message

coingecko coin failed: HTTP ${resp.status}

What it means

This CommandExecutionError is thrown when the CoinGecko API returns a non-OK status other than 404 or 429. Typical statuses include 401 (auth required on pro endpoints), 403 (blocked/forbidden, e.g. Cloudflare block), 5xx (CoinGecko server errors), and 414 (URL too long). The status code is interpolated so the caller can diagnose.

Source

Thrown at clis/coingecko/coin.js:60

        url.searchParams.set('market_data', 'true');
        url.searchParams.set('community_data', 'false');
        url.searchParams.set('developer_data', 'false');
        url.searchParams.set('sparkline', 'false');

        let resp;
        try {
            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
        } catch (error) {
            throw new CommandExecutionError(`coingecko coin request failed: ${error?.message || error}`);
        }
        if (resp.status === 404) {
            throw new EmptyResultError('coingecko coin', `coingecko has no coin with id "${id}".`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError('coingecko returned HTTP 429 (rate limited)', 'Free tier allows ~30 calls/min. Wait and retry.');
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`coingecko coin failed: HTTP ${resp.status}`);
        }
        let data;
        try {
            data = await resp.json();
        } catch (error) {
            throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);
        }
        if (data?.error) {
            throw new CommandExecutionError(`coingecko returned error: ${data.error}`);
        }

        const md = data.market_data || {};
        const pick = (obj, key) => (obj && obj[key] != null ? obj[key] : null);
        const isoFromMaybe = (s) => (s ? String(s).slice(0, 10) : '');
        const price = pick(md.current_price, currency);
        const marketCap = pick(md.market_cap, currency);
        const volume24h = pick(md.total_volume, currency);
        if (price == null && marketCap == null && volume24h == null) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the status code in the message; for 5xx, retry later or check https://status.coingecko.com
  2. For 401/403, verify you're using the public api.coingecko.com endpoint without pro credentials and that your IP isn't blocked
  3. Retry with backoff; if persistent, test `curl -I https://api.coingecko.com/api/v3/ping` to isolate environment vs service issues

Example fix

// before
if (!resp.ok) throw new CommandExecutionError(`coingecko coin failed: HTTP ${resp.status}`);
// after
if (!resp.ok && resp.status >= 500) { await sleep(retryDelay); resp = await fetch(url, opts); } // then keep the throw for still-failing statuses
Defensive patterns

Strategy: try-catch

Validate before calling

const ping = await fetch('https://api.coingecko.com/api/v3/ping').then(r => r.status).catch(() => 0);
if (ping >= 500) console.warn('CoinGecko appears to be having server issues; retry later');

Type guard

null

Try / catch

try { await run(['coingecko', 'coin', id]); } catch (e) { const m = /HTTP (\d{3})/.exec(e.message); if (m && +m[1] >= 500) { await sleep(5000); return retryOnce(); } throw e; }

Prevention

When it happens

Trigger: CoinGecko returning 401/403 (IP blocked by Cloudflare, API key misuse), 500/502/503 (server-side outage or maintenance), or any other unexpected status.

Common situations: CoinGecko partial outages; the client IP being blocked/flagged by Cloudflare bot protection; hitting a deprecated endpoint; proxy injecting error pages.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8a3b491b72956d9e. Report an issue: GitHub.