jackwener/OpenCLI · error · CliError
FETCH_ERROR
FETCH_ERROR
Error message
${detailResp.error || `Failed to fetch topic ${topicId}`} What it means
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.
Source
Thrown at clis/zsxq/topic.js:30
args: [
{ name: 'id', required: true, positional: true, help: 'Topic ID' },
{ name: 'group_id', help: 'Group ID (optional; defaults to active group in Chrome)' },
{ name: 'comment_limit', type: 'int', default: 20, help: 'Number of comments to fetch' },
],
columns: ['topic_id', 'type', 'author', 'title', 'comments', 'likes', 'comment_preview', 'url'],
func: async (page, kwargs) => {
await ensureZsxqPage(page);
await ensureZsxqAuth(page);
const topicId = String(kwargs.id);
const groupId = String(kwargs.group_id || await getActiveGroupId(page));
const commentLimit = Math.max(1, Number(kwargs.comment_limit) || 20);
const detailUrl = `https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}`;
const detailResp = await browserJsonRequest(page, detailUrl);
if (detailResp.status === 404) {
throw new CliError('NOT_FOUND', `Topic ${topicId} not found`);
}
if (!detailResp.ok) {
throw new CliError('FETCH_ERROR', detailResp.error || `Failed to fetch topic ${topicId}`, `Checked endpoint: ${detailUrl}`);
}
const commentsResp = await fetchFirstJson(page, [
`https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}/comments?sort=asc&count=${commentLimit}`,
]);
const topic = getTopicFromResponse(detailResp.data);
if (!topic)
throw new CliError('NOT_FOUND', `Topic ${topicId} not found`);
const comments = getCommentsFromResponse(commentsResp.data);
const row = toTopicRow({
...topic,
comments,
comments_count: topic.comments_count ?? comments.length,
});
return [{
...row,
comment_preview: summarizeComments(comments, 5),
url: getTopicUrl(topic.topic_id ?? topicId),
}];View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
const t = await zsxqTopic({ id }); // hard failure on 429
// after
for (let i = 0; i < 3; i++) {
try { return await zsxqTopic({ id }); }
catch (e) {
if (e.code === 'FETCH_ERROR' && i < 2) { await sleep(2000 * (i + 1)); continue; }
throw e;
}
} Defensive patterns
Strategy: retry
Validate before calling
const r = await page.request.get(`https://api.zsxq.com/v2/groups/${groupId}/topics/${topicId}`);
if (r.status() === 401) await loginZsxq(page); // preflight auth check Type guard
const isFetchError = (e) => e?.code === 'FETCH_ERROR';
Try / catch
try {
return await zsxqTopic({ id });
} catch (e) {
if (isFetchError(e)) {
await sleep(2000);
return zsxqTopic({ id }); // single retry for transient failures
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Session expired mid-run (401); rate limiting from rapid scraping (429); zsxq server errors (5xx); corporate proxy interference.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Failed to fetch Chess.com callback ${url}: ${error?.message
- ${label} request failed: ${err?.message ?? err}. Check that
- ${label} request failed: ${err?.message ?? err}
- mdn search request failed: ${err?.message ?? err}
- network error fetching signed URL: ${e.message}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/86dc4e528bcb5494.
Report an issue: GitHub.