{"record":{"id":"4e823740c2de0c87","repo":"jackwener/OpenCLI","slug":"zhihu-label-request-failed-error-instanceof","errorCode":null,"errorMessage":"Zhihu ${label} request failed: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Zhihu (.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer-comments-helpers.js","lineNumber":53,"sourceCode":"async function fetchCommentPage(page, url, label, notFoundDetail = '') {\n    const evaluated = await page.evaluate(async (requestUrl) => {\n        const response = await fetch(requestUrl, { credentials: 'include' });\n        let body;\n        try {\n            body = await response.json();\n        } catch (error) {\n            return { __httpStatus: response.status, __malformedJson: error instanceof Error ? error.message : String(error) };\n        }\n        const error = body?.error && typeof body.error === 'object' ? body.error : null;\n        const result = {\n            __httpStatus: response.status,\n            __errorCode: error?.code ?? body?.error_code ?? '',\n            __errorMessage: error?.message || body?.error_msg || '',\n            __needLogin: error?.need_login === true || body?.need_login === true,\n        };\n        return !response.ok || result.__errorCode || result.__errorMessage || result.__needLogin ? result : body;\n    }, url).catch((error) => {\n        throw new CommandExecutionError(\n            `Zhihu ${label} request failed: ${error instanceof Error ? error.message : String(error)}`,\n            'Try again later or rerun with -v for more detail.',\n        );\n    });\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.',","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer-comments-helpers.js#L35-L71","documentation":"The in-page Zhihu fetch used to load one page of answer comments rejected or threw, and the .catch wrapper converts any such failure into a CommandExecutionError prefixed with which request type (label) failed and the underlying error message. Detail advice: retry later or rerun with -v.","triggerScenarios":"page.evaluate fetch throws — network outage, Zhihu API returning 4xx/5xx or rate-limiting, anti-bot interstitial blocking the request, CORS/redirect to a login page, or the evaluate itself timing out/crashing inside the browser context.","commonSituations":"Zhihu rate limits after rapid sequential comment paging; anonymous sessions hitting auth-required endpoints; regional blocks or proxy issues; Zhihu changing API contracts so the response shape errors out.","solutions":["Re-run the command; transient network or rate-limit issues often clear on retry","Rerun with -v to get the Detail line and the underlying error message","Slow down / add delay between paginated comment requests to avoid rate limiting","Verify login state if the endpoint requires authentication; re-authenticate the browser profile","Check connectivity/proxy settings if every request fails the same way"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check connectivity/endpoint before paging\nconst res = await fetch(url, { method: 'HEAD' }).catch(() => null);\nif (!res || !res.ok) console.warn('Zhihu endpoint unreachable; expect request failures');","typeGuard":null,"tryCatchPattern":"try {\n  const comments = await cli.zhihuAnswerComments(answerId);\n} catch (e) {\n  if (e.name === 'CommandExecutionError' && /Zhihu .* request failed/.test(e.message)) {\n    await sleep(3000);\n    return retryWithBackoff(() => cli.zhihuAnswerComments(answerId), 3);\n  }\n  throw e;\n}","preventionTips":["Add delays between paginated comment requests to avoid Zhihu rate limiting","Log in within the automation profile if the endpoint requires auth","Wrap page fetches with exponential backoff retry","Run with -v to surface the underlying error message for diagnosis","Monitor for Zhihu API/UI changes that alter response shapes"],"tags":["network","http-request","command-execution","dom-scraping"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}