jackwener/OpenCLI · error · CliError
HTTP_ERROR
HTTP_ERROR
Error message
`sectors failed: HTTP ${resp.status}` What it means
The sectors CLI requests the eastmoney clist API for sector rankings and throws CliError HTTP_ERROR when the response status is not ok, including the status code in the message. Like the rank command, it fails fast before attempting to parse JSON.
Source
Thrown at clis/eastmoney/sectors.js:59
const sortKey = String(args.sort ?? 'change').toLowerCase();
const sort = SORTS[sortKey];
if (!sort) throw new CliError('INVALID_ARGUMENT', `Unknown sort "${sortKey}". Valid: ${Object.keys(SORTS).join(', ')}`);
const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));
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', 'f12,f14,f2,f3,f62,f104,f105,f128,f136,f140,f141');
url.searchParams.set('ut', 'b2884a393a59ad64002292a3e90d46a5');
const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });
if (!resp.ok) throw new CliError('HTTP_ERROR', `sectors 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 sector data');
return diff.slice(0, limit).map((it, i) => ({
rank: i + 1,
code: it.f12,
name: it.f14,
price: it.f2,
changePercent: it.f3,
mainNet: it.f62,
leadStock: it.f128,
leadChangePercent: it.f136,
upCount: it.f104,
downCount: it.f105,
}));
},
});View on GitHub (pinned to 49907e53dc)
Solutions
- Wait and retry; most non-2xx responses are transient
- If status is 403/429, slow down request rate or switch network/egress IP
- Confirm endpoint reachability with curl using a browser User-Agent
- Try different sector type/sort params in case a particular fs value is rejected
Example fix
// before
await fetch(url); // unhandled upstream failure
// after
catch (e) { if (e.code === 'HTTP_ERROR') scheduleRetry(e.message); } Defensive patterns
Strategy: try-catch
Validate before calling
const probe = await fetch('https://push2.eastmoney.com/api/qt/clist/get?pn=1&pz=1', { headers: { 'User-Agent': 'Mozilla/5.0' } }).catch(() => null);
if (!probe || !probe.ok) console.warn('eastmoney unreachable/probable rate limit:', probe?.status); Type guard
function isHttpCliError(e) { return e && e.code === 'HTTP_ERROR'; } Try / catch
try {
const rows = await sectors({ type: 'industry' });
} catch (e) {
if (e.code === 'HTTP_ERROR') {
if (/HTTP 4(29|03)/.test(e.message)) await backoffAndRetry();
else throw e;
} else throw e;
} Prevention
- Throttle polling of the sectors endpoint
- Set a browser-like User-Agent
- Retry with backoff on 429/5xx only
- Cache sector data to reduce request volume
When it happens
Trigger: push2.eastmoney.com returning 403/429/5xx for the sector query — rate limiting, IP/UA blocking, or upstream outage — when running the sectors command.
Common situations: Frequent polling of the sectors endpoint triggering eastmoney rate limits, requests from blocked regions or datacenter IPs, temporary API incidents, proxy interference.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b90e8b9c28ba8335.
Report an issue: GitHub.