{"record":{"id":"1d32717e2f67349b","repo":"jackwener/OpenCLI","slug":"coingecko-returned-error-data-error-1d3271","errorCode":null,"errorMessage":"coingecko returned error: ${data.error}","messagePattern":"coingecko returned error: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/coingecko/top.js","lineNumber":48,"sourceCode":"    url.searchParams.set('order', 'market_cap_desc');\n    url.searchParams.set('per_page', String(limit));\n    url.searchParams.set('page', '1');\n    url.searchParams.set('sparkline', 'false');\n\n    let resp;\n    try {\n      resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n    } catch (error) {\n      throw new CommandExecutionError(`coingecko top request failed: ${error?.message || error}`);\n    }\n    if (!resp.ok) throw new CommandExecutionError(`coingecko top failed: HTTP ${resp.status}`);\n    let data;\n    try {\n      data = await resp.json();\n    } catch (error) {\n      throw new CommandExecutionError(`coingecko returned malformed JSON: ${error?.message || error}`);\n    }\n    if (data?.error) throw new CommandExecutionError(`coingecko returned error: ${data.error}`);\n    if (!Array.isArray(data)) throw new CommandExecutionError('coingecko returned an unexpected response');\n    if (data.length === 0) throw new EmptyResultError('coingecko top', 'coingecko returned no market data');\n\n    return data.map((c) => ({\n      rank: c.market_cap_rank,\n      symbol: String(c.symbol ?? '').toUpperCase(),\n      name: c.name,\n      price: c.current_price,\n      change24hPct: c.price_change_percentage_24h,\n      marketCap: c.market_cap,\n      volume24h: c.total_volume,\n      high24h: c.high_24h,\n      low24h: c.low_24h,\n    }));\n  },\n});\n","sourceCodeStart":30,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coingecko/top.js#L30-L65","documentation":"This CommandExecutionError is thrown when the JSON body parses but contains an { error: ... } field, i.e. CoinGecko returned a structured API error inside a 2xx-style response. The library surfaces the API's own error message verbatim. This is a server-side rejection that must be read from the payload, not from the status code.","triggerScenarios":"CoinGecko responding with JSON like {\"error\":\"Invalid vs_currency\"} or rate-limit/plan messages embedded in the body; deprecated parameter errors returned as JSON.","commonSituations":"Unsupported vs_currency values; demo-key endpoints hit with pro-only parameters; API version drift returning descriptive error objects; bursts hitting soft limits returned as JSON errors.","solutions":["Read the embedded error text in the thrown message — it states the exact API complaint.","Fix the offending parameter (most commonly vs_currency) per the message.","Validate your currency/args against /simple/supported_vs_currencies before calling.","Slow down if the error mentions rate limits or upgrade to a Pro key.","Check CoinGecko changelog if the error indicates a deprecated endpoint/parameter."],"exampleFix":"// before\nawait runCli('coingecko', 'top', ['--currency', 'us dollars']);\n// after\nconst cur = String(rawCur).trim().toLowerCase();\nif (!/^[a-z]{2,6}$/.test(cur)) throw new Error('bad currency: ' + rawCur);\nawait runCli('coingecko', 'top', ['--currency', cur]);","handlingStrategy":"try-catch","validationCode":"const list = await (await fetch('https://api.coingecko.com/api/v3/simple/supported_vs_currencies')).json();\nif (!list.includes(cur)) throw new Error('unsupported vs_currency: ' + cur);","typeGuard":"function isApiErrorPayload(d) { return d !== null && typeof d === 'object' && typeof d.error === 'string'; }","tryCatchPattern":"try {\n  rows = await runCli('coingecko', 'top', opts);\n} catch (e) {\n  if (/coingecko returned error:/.test(e.message)) {\n    console.error('CoinGecko API said:', e.message.replace('coingecko returned error: ', ''));\n  }\n  throw e;\n}","preventionTips":["Validate parameters (especially vs_currency) before each call","Keep query parameters within documented /coins/markets bounds","Upgrade keys if the embedded error mentions plan limits","Follow the CoinGecko changelog for deprecated parameters"],"tags":["api-response","api-error","coingecko","http"],"backgroundTag":"api-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}