{"record":{"id":"f99f41a9030126e6","repo":"jackwener/OpenCLI","slug":"command-exec-f99f41","errorCode":"COMMAND_EXEC","errorMessage":"${apiResult?.message || 'Failed to create answer'}","messagePattern":"\\$\\{apiResult\\?\\.message \\|\\| 'Failed to create answer'\\}","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/answer.js","lineNumber":46,"sourceCode":"        await page.wait(3);\n        const authorIdentity = await resolveCurrentUserIdentity(page);\n        const apiResult = await page.evaluate(`(async () => {\n            var questionId = ${JSON.stringify(target.id)};\n            var content = ${JSON.stringify(payload)};\n            var url = 'https://www.zhihu.com/api/v4/questions/' + questionId + '/answers';\n            var resp = await fetch(url, {\n                method: 'POST',\n                credentials: 'include',\n                headers: { 'Content-Type': 'application/json' },\n                body: JSON.stringify({ content: content, reshipment_settings: 'disallowed' }),\n            });\n            var data = await resp.json();\n            if (!resp.ok) return { ok: false, status: resp.status, message: data.error ? data.error.message : 'unknown error' };\n            if (!data || !data.id) return { ok: false, status: resp.status, message: 'Answer API response did not include a created answer id' };\n            return { ok: true, id: String(data.id), url: data.url || ('https://www.zhihu.com/question/' + questionId + '/answer/' + data.id) };\n        })()`);\n        if (!apiResult?.ok) {\n            throw new CliError('COMMAND_EXEC', apiResult?.message || 'Failed to create answer');\n        }\n        return buildResultRow(`Answered question ${target.id}`, target.kind, rawTarget, 'created', {\n            created_target: 'answer:' + target.id + ':' + apiResult.id,\n            created_url: apiResult.url,\n            author_identity: authorIdentity,\n        });\n    },\n});\n","sourceCodeStart":28,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/answer.js#L28-L55","documentation":"After answering a question, the CLI executes an in-page fetch to Zhihu's answer API. If the result is not ok (non-2xx status, unknown/missing created id, or any thrown message), it throws CliError('COMMAND_EXEC') carrying the API's error message. It means the answer was NOT created — the HTTP call failed or returned an unexpected payload.","triggerScenarios":"The in-page fetch to create the answer returns resp.ok === false (rate limit, auth rejection, question closed, anti-spam challenge); the response JSON lacks an `id`; or the in-page promise rejects so apiResult.ok is false.","commonSituations":"z_c0 cookie expired so the API returns 401/403; posting too frequently triggers Zhihu rate limiting; the target question is closed or restricted; network proxy/firewall blocks the XHR inside the page.","solutions":["Read the embedded message (apiResult.message) for the HTTP status/error text and re-login with `opencli zhihu login` if it indicates 401/403 (expired z_c0 cookie).","Wait and retry later if rate-limited; Zhihu throttles frequent answers.","Verify the question is open and the target id is correct (`question:<id>`).","Inspect the response status in the message; if the page shows a captcha/challenge, complete login/verification in the browser and retry."],"exampleFix":"// before\nthrow new CliError('COMMAND_EXEC', apiResult?.message || 'Failed to create answer');\n// after — caller side handling\ntry {\n  await zhihuAnswer({ target, file });\n} catch (e) {\n  if (/401|403/.test(e.message)) await refreshZhihuLogin();\n  else if (/429|rate/i.test(e.message)) await sleep(60_000);\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!/^question:\\d+$/.test(rawTarget)) throw new Error('target must be question:<id> before answering');","typeGuard":"function isApiResultOk(r) { return !!r && r.ok === true && typeof r.id === 'string'; }","tryCatchPattern":"try { await zhihuAnswer(args); } catch (e) { if (e.code === 'COMMAND_EXEC') { const m = /HTTP (\\d+)/.exec(e.message); if (m && ['401','403'].includes(m[1])) await zhihuLogin(); else if (m && m[1] === '429') await sleep(60_000); } throw e; }","preventionTips":["Keep z_c0 cookie fresh (re-login before long batches)","Avoid rapid-fire answers to dodge rate limits","Validate target format question:<id> before running","Log apiResult message to distinguish auth vs rate-limit vs content errors"],"tags":["zhihu","api","http","command-execution"],"backgroundTag":"api-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}