{"record":{"id":"3d2577f83829fe0a","repo":"jackwener/OpenCLI","slug":"zhihu-collection-request-failed-http-status","errorCode":null,"errorMessage":"Zhihu collection request failed (HTTP ${status})","messagePattern":"Zhihu collection request failed \\(HTTP (.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/collection.js","lineNumber":37,"sourceCode":"  return n;\n}\n\nasync function fetchCollectionPage(page, collectionId, offset, limit) {\n  const url = `https://www.zhihu.com/api/v4/collections/${collectionId}/items?offset=${offset}&limit=${limit}`;\n  const data = await page.evaluate(`\n    (async () => {\n      const r = await fetch(${JSON.stringify(url)}, { credentials: 'include' });\n      if (!r.ok) return { __httpError: r.status };\n      return await r.json();\n    })()\n  `);\n\n  if (!data || data.__httpError) {\n    const status = data?.__httpError;\n    if (status === 401 || status === 403) {\n      throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch collection data from Zhihu. Please ensure you are logged in.');\n    }\n    throw new CommandExecutionError(\n      status ? `Zhihu collection request failed (HTTP ${status})` : 'Zhihu collection request failed',\n      'Try again later or rerun with -v for more detail',\n    );\n  }\n  return data;\n}\n\nfunction itemKey(item) {\n  const content = item?.content || {};\n  return `${content.type || ''}:${content.id || content.url || JSON.stringify(content).slice(0, 80)}`;\n}\n\nfunction mapCollectionItem(item, rank) {\n  const content = item.content || {};\n  const type = content.type || '';\n  if (!['answer', 'article', 'pin'].includes(type)) {\n    throw new CommandExecutionError(\n      `Zhihu collection returned unsupported content type: ${type || 'missing'}`,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/collection.js#L19-L55","documentation":"fetchCollectionPage throws CommandExecutionError when the collection API request failed with a non-401/403 HTTP status (the status is interpolated into the message) or with no usable response at all. It distinguishes transient/network failures from auth failures handled by 5130.","triggerScenarios":"page.evaluate fetch returns __httpError with a status other than 401/403 (e.g. 404 for a nonexistent collection, 429 rate limit, 5xx server error), or data is null/undefined (network failure, page navigation interrupted).","commonSituations":"Typo in the collection ID causing 404; Zhihu returning 429 after rapid repeated calls; transient network outage; Zhihu server-side 5xx during maintenance.","solutions":["Check the HTTP status in the message: 404 means the collection ID is wrong, 429 means slow down","Retry after a delay, especially for 429 or 5xx statuses","Verify the collection ID exists and is public","Rerun with -v for detailed request/response logging"],"exampleFix":"// before\nopencli zhihu collection 8328329  // 404: wrong id\n// after\nopencli zhihu collection 83283292 // correct numeric id","handlingStrategy":"retry","validationCode":"if (!/^\\d+$/.test(String(id))) throw new Error('use a numeric zhihu collection id');","typeGuard":"function isRetryableHttpError(d) {\n  const s = d?.__httpError;\n  return typeof s === 'number' && s !== 401 && s !== 403 && (s === 429 || s >= 500 || s === 0);\n}","tryCatchPattern":"try {\n  return await zhihuCollection(id);\n} catch (e) {\n  if (/HTTP (429|5\\d\\d)/.test(e.message)) { await sleep(backoff); return zhihuCollection(id); }\n  throw e;\n}","preventionTips":["Back off and retry on 429/5xx instead of tight-looping","Verify collection IDs exist and are public before scripting bulk fetches","Handle null responses (network drops) with a bounded retry","Use -v logging to capture status codes for diagnosis"],"tags":["http","network","rate-limit","zhihu"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}