jackwener/OpenCLI · error · CommandExecutionError

coingecko trending failed: HTTP ${resp.status}

Error message

coingecko trending failed: HTTP ${resp.status}

What it means

This CommandExecutionError is thrown when the CoinGecko trending endpoint returns a response whose status is not OK and not 429 — i.e. any other HTTP error status (403, 500, 502, 503, etc.). The message interpolates the actual status code so the developer can see exactly what the server returned. It comes after the fetch succeeded but the server rejected or failed the request at the HTTP layer.

Source

Thrown at clis/coingecko/trending.js:30

    description: 'Top trending cryptocurrencies on CoinGecko in the last 24h (search-volume based).',
    domain: 'api.coingecko.com',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [],
    columns: ['rank', 'id', 'symbol', 'name', 'marketCapRank', 'priceBtc', 'thumb'],
    func: async () => {
        const url = 'https://api.coingecko.com/api/v3/search/trending';
        let resp;
        try {
            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
        } catch (error) {
            throw new CommandExecutionError(`coingecko trending request failed: ${error?.message || error}`);
        }
        if (resp.status === 429) {
            throw new CommandExecutionError('coingecko returned HTTP 429 (rate limited)', 'Wait and retry.');
        }
        if (!resp.ok) {
            throw new CommandExecutionError(`coingecko trending failed: HTTP ${resp.status}`);
        }
        let data;
        try {
            data = await resp.json();
        } catch (error) {
            throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);
        }
        const coins = Array.isArray(data?.coins) ? data.coins : [];
        if (coins.length === 0) {
            throw new EmptyResultError('coingecko trending', 'coingecko returned no trending coins.');
        }
        return coins.map((entry, i) => {
            const c = entry?.item || {};
            return {
                rank: i + 1,
                id: c.id || '',
                symbol: String(c.symbol || '').toUpperCase(),
                name: c.name || '',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the interpolated HTTP status in the message: 5xx means wait/retry (server-side), 403 means your client is being blocked
  2. If 403, test with curl using a full realistic User-Agent; consider CoinGecko's official API with a key instead of the spoofed-UA public endpoint
  3. Check https://status.coingecko.com for outages causing 5xx responses
  4. Add retry-with-backoff around the command for transient 5xx responses

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

function isHttpError(e) {
  const m = /HTTP (\d{3})/.exec(e?.message || '');
  return m ? { status: Number(m[1]), isServer: Number(m[1]) >= 500, isForbidden: m[1] === '403' } : null;
}

Try / catch

try {
  await runCli('coingecko trending');
} catch (e) {
  const st = isHttpError(e);
  if (st?.isServer) return retryWithBackoff(() => runCli('coingecko trending'));
  if (st?.isForbidden) throw new Error('Blocked by CoinGecko/Cloudflare: use official API with key');
  throw e;
}

Prevention

When it happens

Trigger: `resp.ok` is false and `resp.status !== 429` after fetching https://api.coingecko.com/api/v3/search/trending. Typical statuses: 403 (blocked/WAF, often when the User-Agent heuristic is rejected by Cloudflare), 500/502/503 (CoinGecko server-side issues), 404 if the API path changed.

Common situations: CoinGecko outage or degraded service returning 5xx, Cloudflare bot protection challenging requests with the spoofed Mozilla/5.0 UA (403), corporate proxies injecting error pages, or CoinGecko deprecating/renaming the API path.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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