{"record":{"id":"86dc4e528bcb5494","repo":"jackwener/OpenCLI","slug":"fetch-error-86dc4e","errorCode":"FETCH_ERROR","errorMessage":"${detailResp.error || `Failed to fetch topic ${topicId}`}","messagePattern":"\\$\\{detailResp\\.error \\|\\| `Failed to fetch topic \\$\\{topicId\\}`\\}","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zsxq/topic.js","lineNumber":30,"sourceCode":"    args: [\n        { name: 'id', required: true, positional: true, help: 'Topic ID' },\n        { name: 'group_id', help: 'Group ID (optional; defaults to active group in Chrome)' },\n        { name: 'comment_limit', type: 'int', default: 20, help: 'Number of comments to fetch' },\n    ],\n    columns: ['topic_id', 'type', 'author', 'title', 'comments', 'likes', 'comment_preview', 'url'],\n    func: async (page, kwargs) => {\n        await ensureZsxqPage(page);\n        await ensureZsxqAuth(page);\n        const topicId = String(kwargs.id);\n        const groupId = String(kwargs.group_id || await getActiveGroupId(page));\n        const commentLimit = Math.max(1, Number(kwargs.comment_limit) || 20);\n        const detailUrl = `https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}`;\n        const detailResp = await browserJsonRequest(page, detailUrl);\n        if (detailResp.status === 404) {\n            throw new CliError('NOT_FOUND', `Topic ${topicId} not found`);\n        }\n        if (!detailResp.ok) {\n            throw new CliError('FETCH_ERROR', detailResp.error || `Failed to fetch topic ${topicId}`, `Checked endpoint: ${detailUrl}`);\n        }\n        const commentsResp = await fetchFirstJson(page, [\n            `https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}/comments?sort=asc&count=${commentLimit}`,\n        ]);\n        const topic = getTopicFromResponse(detailResp.data);\n        if (!topic)\n            throw new CliError('NOT_FOUND', `Topic ${topicId} not found`);\n        const comments = getCommentsFromResponse(commentsResp.data);\n        const row = toTopicRow({\n            ...topic,\n            comments,\n            comments_count: topic.comments_count ?? comments.length,\n        });\n        return [{\n                ...row,\n                comment_preview: summarizeComments(comments, 5),\n                url: getTopicUrl(topic.topic_id ?? topicId),\n            }];","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zsxq/topic.js#L12-L48","documentation":"When the topic detail request fails with any non-404, non-OK status (or a transport error surfaced by browserJsonRequest), the library throws CliError('FETCH_ERROR', detailResp.error || `Failed to fetch topic ${topicId}`, `Checked endpoint: ${detailUrl}`). The third argument records the exact endpoint that was checked for debugging.","triggerScenarios":"GET /v2/groups/{groupId}/topics/{topicId} returns 401/403/429/5xx or a network-level failure; any status other than 404 and 2xx triggers this branch.","commonSituations":"Session expired mid-run (401); rate limiting from rapid scraping (429); zsxq server errors (5xx); corporate proxy interference.","solutions":["Read the error detail/hint ('Checked endpoint: ...') and reproduce the URL in a logged-in browser to see the raw status.","Re-authenticate if the status is 401/403 — run the zsxq login flow again.","Back off and retry on 429/5xx; add delays between topic fetches to avoid rate limits.","Retry the command — transient network/server failures often resolve on a second attempt."],"exampleFix":"// before\nconst t = await zsxqTopic({ id }); // hard failure on 429\n// after\nfor (let i = 0; i < 3; i++) {\n  try { return await zsxqTopic({ id }); }\n  catch (e) {\n    if (e.code === 'FETCH_ERROR' && i < 2) { await sleep(2000 * (i + 1)); continue; }\n    throw e;\n  }\n}","handlingStrategy":"retry","validationCode":"const r = await page.request.get(`https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}`);\nif (r.status() === 401) await loginZsxq(page); // preflight auth check","typeGuard":"const isFetchError = (e) => e?.code === 'FETCH_ERROR';","tryCatchPattern":"try {\n  return await zsxqTopic({ id });\n} catch (e) {\n  if (isFetchError(e)) {\n    await sleep(2000);\n    return zsxqTopic({ id }); // single retry for transient failures\n  }\n  throw e;\n}","preventionTips":["Add delays between topic fetches to avoid rate limiting.","Re-authenticate when you see 401/403 in the error detail.","Log the 'Checked endpoint' hint to reproduce failures against the exact URL."],"tags":["fetch","http","network"],"backgroundTag":"http-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}