jackwener/OpenCLI · error · CliError

HTTP_ERROR

HTTP_ERROR

Error message

`eastmoney rank failed: HTTP ${resp.status}`

What it means

The eastmoney rank CLI fetches stock ranking data from the push2.eastmoney.com clist API. It throws this CliError with code HTTP_ERROR whenever the HTTP response status is not ok (e.g. 4xx/5xx), aborting before JSON parsing so the caller gets a clear upstream-failure message with the status code.

Source

Thrown at clis/eastmoney/rank.js:74

    const sort = SORTS[sortKey];
    if (!sort) {
      throw new CliError('INVALID_ARGUMENT', `Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(', ')}`);
    }

    const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');
    url.searchParams.set('pn', '1');
    url.searchParams.set('pz', String(limit));
    url.searchParams.set('po', sort.order === 'desc' ? '1' : '0');
    url.searchParams.set('np', '1');
    url.searchParams.set('fltt', '2');
    url.searchParams.set('invt', '2');
    url.searchParams.set('fid', sort.fid);
    url.searchParams.set('fs', fs);
    url.searchParams.set('fields', FIELDS);
    url.searchParams.set('ut', 'bd1d9ddb04089700cf9c27f6f7426281');

    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0', Accept: 'application/json' } });
    if (!resp.ok) throw new CliError('HTTP_ERROR', `eastmoney rank failed: HTTP ${resp.status}`);
    const data = await resp.json();
    const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];
    if (diff.length === 0) {
      throw new CliError('NO_DATA', 'eastmoney returned no rank data', `market=${market} sort=${sortKey}`);
    }

    return diff.slice(0, limit).map((it, i) => ({
      rank: i + 1,
      code: it.f12,
      name: it.f14,
      price: it.f2,
      changePercent: it.f3,
      change: it.f4,
      turnover: it.f6,
      volume: it.f5,
      turnoverRate: it.f8,
      peDynamic: it.f9,
      marketCap: it.f20,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command after a short wait; the failure is usually transient
  2. Check the HTTP status in the message: 403/429 means blocked or rate-limited — reduce request frequency or change network/IP (VPN/proxy)
  3. Verify network access to push2.eastmoney.com (curl -I with a browser User-Agent)
  4. Retry with a different market/sort parameter in case a specific query combination is rejected

Example fix

// before: raw fetch failure surfaces as generic fetch error
const resp = await fetch(url);
// after (library already does this; caller should catch)
try { await rank({ market: 'hsa', sort: 'change' }); } catch (e) { if (e.code === 'HTTP_ERROR') console.error('eastmoney unavailable:', e.message); }
Defensive patterns

Strategy: try-catch

Validate before calling

const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');
// preflight reachability
const ping = await fetch(url, { method: 'HEAD' }).catch(() => null);
if (!ping || !ping.ok) console.warn('eastmoney endpoint not reachable, status', ping?.status);

Type guard

function isHttpCliError(e) { return e && typeof e === 'object' && e.code === 'HTTP_ERROR' && typeof e.message === 'string'; }

Try / catch

try {
  const rows = await rank({ market: 'hsa', sort: 'change' });
} catch (e) {
  if (e.code === 'HTTP_ERROR') {
    const status = /HTTP (\d{3})/.exec(e.message)?.[1];
    if (status === '429' || status?.startsWith('5')) await retryWithBackoff();
    else console.error('eastmoney rejected request:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Any non-2xx response from https://push2.eastmoney.com/api/qt/clist/get while running the rank command — e.g. the eastmoney API rate-limits, blocks the UA/IP, returns 403/429, or the endpoint is temporarily down.

Common situations: Running the CLI from an IP region blocked by eastmoney, hammering the endpoint in a loop and hitting rate limiting, eastmoney serving HTML error pages during outages, or a corporate proxy returning 4xx/5xx.

Related errors


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