{"record":{"id":"60e89e6ec61696af","repo":"jackwener/OpenCLI","slug":"zhihu-user-request-failed-http-status","errorCode":null,"errorMessage":"Zhihu user request failed (HTTP ${status})","messagePattern":"Zhihu user request failed \\(HTTP (.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/user.js","lineNumber":42,"sourceCode":"      (async () => {\n        try {\n          const r = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });\n          if (!r.ok) return { __httpError: r.status };\n          return await r.json();\n        } catch (err) {\n          return { __fetchError: err?.message || String(err) };\n        }\n      })()\n    `));\n        if (!data || typeof data !== 'object' || Array.isArray(data) || data.__httpError || data.__fetchError) {\n            const status = data?.__httpError;\n            if (status === 401 || status === 403) {\n                throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu user profile');\n            }\n            if (status === 404) {\n                throw new EmptyResultError('zhihu user', `No Zhihu user was found for ${slug}.`);\n            }\n            throw new CommandExecutionError(status ? `Zhihu user request failed (HTTP ${status})` : 'Zhihu user request failed', data?.__fetchError ? String(data.__fetchError) : 'Try again later or rerun with -v');\n        }\n        if (!data.url_token || !data.id || !data.name) {\n            throw new CommandExecutionError('Zhihu user response missing identity fields', 'Zhihu may have changed its API shape');\n        }\n        return [{\n            url_token: String(data.url_token || ''),\n            name: String(data.name || ''),\n            headline: String(data.headline || ''),\n            followers: data.follower_count ?? 0,\n            following: data.following_count ?? 0,\n            answers: data.answer_count ?? 0,\n            articles: data.articles_count ?? 0,\n            voteup: data.voteup_count ?? 0,\n            url: data.url_token ? `https://www.zhihu.com/people/${data.url_token}` : '',\n        }];\n    },\n});\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/user.js#L24-L60","documentation":"When the in-page fetch returns an HTTP status other than 401/403/404 (or no recognizable data), the user command throws CommandExecutionError 'Zhihu user request failed (HTTP <status>)'. It is the generic transport/HTTP failure branch for the Zhihu profile fetch.","triggerScenarios":"Any non-401/403/404 status from www.zhihu.com during the profile fetch: 429 rate-limiting, 5xx server errors, redirects to verification pages, or data=null with no __httpError/__fetchError classification.","commonSituations":"Aggressive polling of the Zhihu API leading to 429; Zhihu incidents returning 5xx; anti-bot challenges returning unusual statuses; network proxies mangling requests.","solutions":["Retry after a delay (especially for 429/5xx)","Reduce request frequency / add backoff between calls","Rerun with -v to see the underlying cause recorded as the secondary message","Re-login if the session state is suspect (unclassified statuses can mask auth issues)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function fetchUserWithRetry(slug, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await fetchZhihuUser(slug); }\n    catch (e) {\n      if (/HTTP (429|5\\d\\d)/.test(e.message) && i < attempts - 1) {\n        await sleep(1000 * 2 ** i); continue;\n      }\n      throw e;\n    }\n  }\n}","preventionTips":["Add exponential backoff and honor 429s","Throttle request rate across jobs hitting www.zhihu.com","Run with -v to capture the secondary error detail for triage","Alert on repeated 5xx so Zhihu incidents are noticed"],"tags":["http","network","zhihu"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}