{"record":{"id":"5aec0af6a0496063","repo":"jackwener/OpenCLI","slug":"www-zhihu-com-5aec0a","errorCode":null,"errorMessage":"www.zhihu.com","messagePattern":"www\\.zhihu\\.com","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/search.js","lineNumber":83,"sourceCode":"        throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');\n    }\n    return type;\n}\n\nfunction unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;\n    return payload;\n}\n\nfunction requireSearchPayload(data, url) {\n    const payload = unwrapEvaluateResult(data);\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('Zhihu search returned malformed payload');\n    }\n    if (payload.__httpError) {\n        const status = payload.__httpError;\n        if (status === 401 || status === 403) {\n            throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');\n        }\n        throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');\n    }\n    if (payload.__fetchError) {\n        throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));\n    }\n    if (!Array.isArray(payload.data)) {\n        throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);\n    }\n    if (!payload.paging || typeof payload.paging !== 'object') {\n        throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);\n    }\n    return payload;\n}\n\nfunction normalizeResultItem(item) {\n    if (!item || typeof item !== 'object' || item.type !== 'search_result' || !item.object || typeof item.object !== 'object') {\n        return null;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/search.js#L65-L101","documentation":"This AuthRequiredError is thrown by requireSearchPayload when the Zhihu search response carries __httpError with status 401 or 403, meaning Zhihu refused the request because the session lacks valid authentication. The 'www.zhihu.com' message is the host marker for the auth-requirement error; the remedy is signing in via the connected Chrome profile.","triggerScenarios":"Running zhihu search while logged out (or with expired Zhihu cookies) and the in-page fetch of the search API returns HTTP 401/403, surfacing as payload.__httpError.","commonSituations":"Zhihu session expired after days of inactivity; using a clean/incognito Chrome profile with no login; Zhihu now requiring login for search; cookies cleared by browser hygiene tooling.","solutions":["Open www.zhihu.com in the connected Chrome profile and log in (scan QR if needed), then rerun the search","Clear the risk-control state by browsing manually once, then retry","If recently logged in but still 401/403, check for cookie-clearing extensions or privacy settings","Retry later if Zhihu is enforcing temporary login walls on search"],"exampleFix":"// before: retrying blindly on auth error\nawait searchZhihu(q);\n// after\ncatch (err) {\n  if (err instanceof AuthRequiredError) {\n    console.error('Log in to www.zhihu.com in the connected Chrome profile, then rerun.');\n    return;\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight: check the session is authenticated\nconst me = await bridge.evaluate(\"fetch('https://www.zhihu.com/api/v4/me').then(r => r.status)\");\nif (me === 401) throw new Error('Log in to www.zhihu.com in the connected Chrome profile first');","typeGuard":"function isAuthRequiredError(err) {\n  return err instanceof AuthRequiredError || (err instanceof Error && err.message.includes('www.zhihu.com'));\n}","tryCatchPattern":"try {\n  const results = await searchZhihu(q);\n} catch (err) {\n  if (isAuthRequiredError(err)) {\n    console.error('Zhihu session expired. Sign in at www.zhihu.com in the connected Chrome profile, then rerun.');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Periodically confirm you are still logged in on www.zhihu.com in the automation profile","Keep cookies persistent by using a dedicated (non-incognito) Chrome profile","Disable cookie-clearing extensions or 'clear on exit' browser settings","Re-login proactively before long batch jobs"],"tags":["zhihu","authentication","http-401","http-403","session-expired"],"backgroundTag":"authentication-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}