{"record":{"id":"94f8168f705d37f1","repo":"jackwener/OpenCLI","slug":"http-code-94f816","errorCode":null,"errorMessage":"HTTP ${code}","messagePattern":"HTTP \\$\\{code\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xueqiu/utils.js","lineNumber":55,"sourceCode":"    const result = await page.evaluate(`(async () => {\n    const res = await fetch(${JSON.stringify(url)}, { credentials: 'include' });\n    if (!res.ok) return { __xqErr: res.status };\n    try {\n      return await res.json();\n    } catch {\n      return { __xqErr: 'parse' };\n    }\n  })()`);\n    const r = result;\n    if (r?.__xqErr !== undefined) {\n        const code = r.__xqErr;\n        if (code === 401 || code === 403) {\n            throw new AuthRequiredError('xueqiu.com', '未登录或登录已过期');\n        }\n        if (code === 'parse') {\n            throw new CommandExecutionError('响应不是有效 JSON', '可能触发了风控，请检查登录状态或稍后重试');\n        }\n        throw new CommandExecutionError(`HTTP ${code}`, '请检查网络连接或登录状态');\n    }\n    return result;\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xueqiu/utils.js#L37-L59","documentation":"fetchXueqiuJson maps any non-ok HTTP status other than 401/403 to CommandExecutionError(`HTTP ${code}`). This is the generic branch for server-side failures (4xx/5xx) from xueqiu's API — e.g. 400 bad pid parameter, 404 unknown endpoint, 500/502 server trouble. It is thrown so callers get a clean CliError with an actionable hint instead of an opaque network failure.","triggerScenarios":"xueqiu API returns status codes like 400 (invalid pid param), 404, 429 (rate limited), or 5xx; any status that is not 200, 401, or 403 and whose body cannot be parsed as valid JSON data.","commonSituations":"Passing an invalid pid group id; xueqiu API temporarily down or returning 502; rate limiting (429) after rapid calls; endpoint changed server-side.","solutions":["Check network connectivity and retry","Verify the pid / query parameters are valid (get group ids via xueqiu groups)","Wait and retry if the status is 429 or 5xx (server-side or rate limit)","Re-login if the error persists alongside other auth symptoms"],"exampleFix":"// before (invalid pid)\nconst url = `...&pid=${encodeURIComponent('abc')}`; // HTTP 400\n// after (validate pid first)\nconst valid = ['-1','-4','-5','-6','-7','-10','0'];\nif (!valid.includes(pid)) throw new Error(`invalid pid: ${pid}`);\nconst url = `...&pid=${encodeURIComponent(pid)}`;","handlingStrategy":"retry","validationCode":"if (!/^-?\\d+$/.test(pid)) throw new Error(`invalid pid: ${pid}`);","typeGuard":"function isCommandExecutionError(e) { return e instanceof CommandExecutionError; }","tryCatchPattern":"try {\n  const d = await fetchXueqiuJson(page, url);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /^HTTP \\d+/.test(e.message)) {\n    const status = Number(e.message.match(/HTTP (\\d+)/)[1]);\n    if (status === 429 || status >= 500) return retryWithBackoff(() => fetchXueqiuJson(page, url));\n  }\n  throw e;\n}","preventionTips":["Validate query parameters (pid, size) before building the URL","Retry with backoff only on 429/5xx, not on 4xx","Monitor xueqiu API availability before bulk operations","Keep request rates low to avoid 429 rate limiting"],"tags":["http","network","xueqiu","api-error"],"backgroundTag":"http-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}