{"record":{"id":"bdaf41c8c5203d24","repo":"jackwener/OpenCLI","slug":"www-zhihu-com","errorCode":null,"errorMessage":"www.zhihu.com","messagePattern":"www\\.zhihu\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":401,"severity":"error","filePath":"clis/zhihu/answer-comments-helpers.js","lineNumber":75,"sourceCode":"    });\n    const payload = unwrapEvaluateResult(evaluated);\n    if (payload?.__malformedJson) {\n        throw new CommandExecutionError(`Zhihu ${label} returned malformed JSON: ${payload.__malformedJson}`);\n    }\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError(`Zhihu ${label} returned a malformed payload`);\n    }\n    const status = payload.__httpStatus;\n    const code = String(payload.__errorCode || '');\n    if (status >= 400 || code || payload.__errorMessage || payload.__needLogin) {\n        if (code === '40362') {\n            throw new CommandExecutionError(\n                `Zhihu risk control blocked ${label} (40362): ${payload.__errorMessage || 'abnormal request'}`,\n                'Open the answer in the connected Chrome profile and retry later.',\n            );\n        }\n        if (status === 401 || status === 403 || code === '40353' || payload.__needLogin) {\n            throw new AuthRequiredError('www.zhihu.com', `Failed to fetch Zhihu ${label}`);\n        }\n        if (status === 404 && notFoundDetail) throw new EmptyResultError('zhihu answer-comments', notFoundDetail);\n        if (status >= 400) throw new CommandExecutionError(`Zhihu ${label} request failed (HTTP ${status})`);\n        throw new CommandExecutionError(`Zhihu ${label} returned an error payload: ${payload.__errorMessage || code}`);\n    }\n    if (!Array.isArray(payload.data) || !payload.paging || typeof payload.paging !== 'object') {\n        throw new CommandExecutionError(`Zhihu ${label} returned a malformed payload`);\n    }\n    if (typeof payload.paging.is_end !== 'boolean') {\n        throw new CommandExecutionError(`Zhihu ${label} returned malformed paging state`);\n    }\n    return payload;\n}\nfunction describeComment(comment, role, expectedRootId = '') {\n    if (!comment || typeof comment !== 'object' || Array.isArray(comment)) {\n        throw new CommandExecutionError(`Zhihu answer comments contained a malformed ${role} row`);\n    }\n    const id = commentId(comment.id);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments-helpers.js#L57-L93","documentation":"AuthRequiredError raised with host 'www.zhihu.com' when the comment fetch indicates an authentication problem: HTTP 401/403, errorCode 40353, or payload.__needLogin. The library signals that valid Zhihu login credentials in the connected Chrome profile are required before the command can succeed.","triggerScenarios":"The comment endpoint returned status 401 or 403, or __errorCode '40353', or __needLogin was set — Zhihu says the session is not authenticated (or no longer valid) for this resource.","commonSituations":"Chrome profile logged out of Zhihu; session cookie expired; fetching members-only or otherwise restricted content anonymously; profile cookies cleared by browser cleanup.","solutions":["Open www.zhihu.com in the connected Chrome profile and log in, then rerun the command","Refresh the profile's session cookies (re-login) if it was previously authenticated","Check that the content is not inherently login-only (e.g. restricted answers)","Use a profile with an active Zhihu account rather than a fresh one"],"exampleFix":"// before\nawait cli('--answer-url', url); // fails with AuthRequiredError on stale profile\n// after\n// precondition: ensure login first\nif (!(await isZhihuLoggedIn(profile))) await openBrowserAndLogin('https://www.zhihu.com/signin');\nawait cli('--answer-url', url);","handlingStrategy":"try-catch","validationCode":"const cookies = await profileCookies(); if (!cookies.some(c => c.name === 'z_c0' && c.domain.includes('zhihu.com'))) throw new Error('Zhihu session missing — log in first');","typeGuard":"function isAuthError(e){ return e instanceof AuthRequiredError || /401|403|40353|needLogin/i.test(String(e.message)); }","tryCatchPattern":"try { await fetchCommentPage(url); } catch (e) { if (isAuthError(e)) { await promptUserToLogin('https://www.zhihu.com'); return fetchCommentPage(url); } throw e; }","preventionTips":["Verify a z_c0 session cookie exists in the profile before running","Re-login periodically; sessions expire","Check content availability anonymously if 403 persists after login","Avoid cookie-clearing browser automation between runs"],"tags":["zhihu","auth","login-required","session-expired"],"backgroundTag":"auth-required-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}