{"record":{"id":"a9eb2a312ba48c1d","repo":"jackwener/OpenCLI","slug":"zhihu-label-returned-an-error-payload-payloa","errorCode":null,"errorMessage":"Zhihu ${label} returned an error payload: ${payload.__errorMessage || code}","messagePattern":"Zhihu (.+?) returned an error payload: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-comments-helpers.js","lineNumber":79,"sourceCode":"    }\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);\n    if (!id) throw new CommandExecutionError(`Zhihu answer comments contained a ${role} row without a stable id`);\n    const rootId = role === 'root' ? id : commentId(comment.reply_root_comment_id);\n    const parentId = role === 'root' ? '' : commentId(comment.reply_comment_id);\n    if (role === 'child' && rootId !== expectedRootId) {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments-helpers.js#L61-L97","documentation":"CommandExecutionError raised when Zhihu returned an error payload that carried no HTTP failure status but did include an error indication (__errorMessage or __errorCode) not covered by the special cases. The message surfaces Zhihu's own error text or code so the developer can see why the API refused the logical request.","triggerScenarios":"status < 400 but payload.__errorMessage or __errorCode set (and not 40362/40353/needLogin) — Zhihu returning 200 with a business-logic error body, or a payload whose shape regressed.","commonSituations":"Zhihu API returning {error: ...} bodies with 200; new error codes after API changes; comment feature disabled for the answer; malformed request producing an app-level error.","solutions":["Read the surfaced __errorMessage/__errorCode in the message to identify the business error","Compare the code against Zhihu API docs; add handling if it's a new known code","Verify the request parameters (answer id, sort, order) are still valid","Capture the full payload with -v and check for API schema changes"],"exampleFix":"// before\nthrow new CommandExecutionError(`... error payload: ${payload.__errorMessage || code}`);\n// after\n// at call site, branch on the code for better handling\ncatch (e) { if (e.message.includes('100001')) retryWithBackoff(); else throw e; }","handlingStrategy":"try-catch","validationCode":"// validate parameters before request\nif (!/^\\d+$/.test(answerId)) throw new Error('invalid answer id');","typeGuard":"function isBusinessError(e){ return /error payload/i.test(String(e.message)); }","tryCatchPattern":"try { await fetchCommentPage(url); } catch (e) { const m = e.message.match(/error payload: (.+)$/); if (m) { log(`Zhihu business error: ${m[1]}`); /* map known codes to handling */ } throw e; }","preventionTips":["Log full payloads with -v to learn new error codes","Keep a code->action map updated against Zhihu API docs","Validate ids/sort/order params before requests","Watch for API schema changes after Zhihu releases"],"tags":["zhihu","api-error","business-logic","error-code"],"backgroundTag":"api-error-code-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}