{"record":{"id":"ef3d2fb6be1e39eb","repo":"jackwener/OpenCLI","slug":"toutiao-recommend-returned-message-payload-messa","errorCode":null,"errorMessage":"toutiao recommend returned message=${payload.message}","messagePattern":"toutiao recommend returned message=(.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/toutiao/recommend.js","lineNumber":61,"sourceCode":"                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',\n                    Accept: 'application/json',\n                    Referer: 'https://www.toutiao.com/',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`toutiao recommend request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`toutiao recommend failed: HTTP ${resp.status}`);\n        }\n        let payload;\n        try {\n            payload = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`toutiao recommend returned malformed JSON: ${error?.message || error}`);\n        }\n        if (payload?.message && payload.message !== 'success') {\n            throw new CommandExecutionError(`toutiao recommend returned message=${payload.message}`);\n        }\n        if (!Array.isArray(payload?.data)) {\n            throw new CommandExecutionError('toutiao recommend returned a non-array data field');\n        }\n        const rows = payload.data.map(mapRecommendRow).filter(Boolean).slice(0, limit);\n        if (rows.length === 0) {\n            throw new EmptyResultError('toutiao recommend', `频道 ${category} 返回空列表。`);\n        }\n        // Re-rank (1..N) after filter so ranks are dense even if upstream had ads.\n        return rows.map((row, idx) => ({ ...row, rank: idx + 1 }));\n    },\n});\n","sourceCodeStart":43,"sourceCodeEnd":74,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/recommend.js#L43-L74","documentation":"This CommandExecutionError is thrown when the toutiao recommend payload contains a message field whose value is not 'success'. The upstream API signals business-level failures inside a 200 JSON body via this message field, and the library surfaces it verbatim.","triggerScenarios":"Calling 'toutiao recommend' when the parsed JSON has payload.message set to anything other than 'success' — e.g. risk-control rejections, quota/permission errors, or other upstream business errors.","commonSituations":"Toutiao risk-control flagging the request as automated; API contract change introducing a new message value the check does not recognize; regional restrictions reported via message instead of HTTP status.","solutions":["Read the embedded message value to learn what upstream rejected (it is printed verbatim in the error).","Slow down request rate and add cookies/headers if the message indicates risk control or frequency limits.","If upstream legitimately changed its success marker, update the `payload.message !== 'success'` check in recommend.js to match the new contract.","Retry later if the message indicates a temporary upstream condition."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await recommend({ category });\n} catch (e) {\n  const m = /returned message=(.+)/.exec(e.message);\n  if (m) {\n    console.error('Upstream business error:', m[1]);\n    return []; // degrade gracefully\n  }\n  throw e;\n}","preventionTips":["Surface the embedded message verbatim when logging — it names the upstream rejection reason.","Slow down and add cookies if messages indicate risk control.","Watch for new message values after upstream API updates.","Pin library versions and read changelogs for upstream contract changes."],"tags":["upstream-api","business-error","api-contract"],"backgroundTag":"upstream-api-business-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}