{"record":{"id":"b90e8b9c28ba8335","repo":"jackwener/OpenCLI","slug":"http-error-b90e8b","errorCode":"HTTP_ERROR","errorMessage":"`sectors failed: HTTP ${resp.status}`","messagePattern":"`sectors failed: HTTP (.+?)`","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/eastmoney/sectors.js","lineNumber":59,"sourceCode":"    const sortKey = String(args.sort ?? 'change').toLowerCase();\n    const sort = SORTS[sortKey];\n    if (!sort) throw new CliError('INVALID_ARGUMENT', `Unknown sort \"${sortKey}\". Valid: ${Object.keys(SORTS).join(', ')}`);\n    const limit = Math.max(1, Math.min(Number(args.limit) || 20, 100));\n\n    const url = new URL('https://push2.eastmoney.com/api/qt/clist/get');\n    url.searchParams.set('pn', '1');\n    url.searchParams.set('pz', String(limit));\n    url.searchParams.set('po', sort.order === 'desc' ? '1' : '0');\n    url.searchParams.set('np', '1');\n    url.searchParams.set('fltt', '2');\n    url.searchParams.set('invt', '2');\n    url.searchParams.set('fid', sort.fid);\n    url.searchParams.set('fs', fs);\n    url.searchParams.set('fields', 'f12,f14,f2,f3,f62,f104,f105,f128,f136,f140,f141');\n    url.searchParams.set('ut', 'b2884a393a59ad64002292a3e90d46a5');\n\n    const resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n    if (!resp.ok) throw new CliError('HTTP_ERROR', `sectors failed: HTTP ${resp.status}`);\n    const data = await resp.json();\n    const diff = Array.isArray(data?.data?.diff) ? data.data.diff : [];\n    if (diff.length === 0) throw new CliError('NO_DATA', 'eastmoney returned no sector data');\n\n    return diff.slice(0, limit).map((it, i) => ({\n      rank: i + 1,\n      code: it.f12,\n      name: it.f14,\n      price: it.f2,\n      changePercent: it.f3,\n      mainNet: it.f62,\n      leadStock: it.f128,\n      leadChangePercent: it.f136,\n      upCount: it.f104,\n      downCount: it.f105,\n    }));\n  },\n});","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/eastmoney/sectors.js#L41-L77","documentation":"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.","triggerScenarios":"push2.eastmoney.com returning 403/429/5xx for the sector query — rate limiting, IP/UA blocking, or upstream outage — when running the sectors command.","commonSituations":"Frequent polling of the sectors endpoint triggering eastmoney rate limits, requests from blocked regions or datacenter IPs, temporary API incidents, proxy interference.","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"],"exampleFix":"// before\nawait fetch(url); // unhandled upstream failure\n// after\ncatch (e) { if (e.code === 'HTTP_ERROR') scheduleRetry(e.message); }","handlingStrategy":"try-catch","validationCode":"const probe = await fetch('https://push2.eastmoney.com/api/qt/clist/get?pn=1&pz=1', { headers: { 'User-Agent': 'Mozilla/5.0' } }).catch(() => null);\nif (!probe || !probe.ok) console.warn('eastmoney unreachable/probable rate limit:', probe?.status);","typeGuard":"function isHttpCliError(e) { return e && e.code === 'HTTP_ERROR'; }","tryCatchPattern":"try {\n  const rows = await sectors({ type: 'industry' });\n} catch (e) {\n  if (e.code === 'HTTP_ERROR') {\n    if (/HTTP 4(29|03)/.test(e.message)) await backoffAndRetry();\n    else throw e;\n  } else throw e;\n}","preventionTips":["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"],"tags":["http","network","api","eastmoney"],"backgroundTag":"upstream-http-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}