{"record":{"id":"fb6c384472733d61","repo":"jackwener/OpenCLI","slug":"toutiao-recommend-request-failed-error-message","errorCode":null,"errorMessage":"toutiao recommend request failed: ${error?.message || error}","messagePattern":"toutiao recommend request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/toutiao/recommend.js","lineNumber":49,"sourceCode":"        { name: 'category', type: 'string', default: '__all__', help: `频道 (${RECOMMEND_CATEGORIES.join(', ')})` },\n        { name: 'limit', type: 'int', default: 20, help: '返回条数 (1-50)' },\n    ],\n    columns: ['rank', 'group_id', 'title', 'abstract', 'source', 'tag', 'comments', 'published_at', 'url', 'image_url'],\n    func: async (kwargs) => {\n        const category = parseRecommendCategory(kwargs?.category, '__all__');\n        const limit = parseRecommendLimit(kwargs?.limit, 20);\n        const url = `${RECOMMEND_URL}?category=${encodeURIComponent(category)}`;\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    '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) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/recommend.js#L31-L67","documentation":"This CommandExecutionError wraps any network/transport failure of the fetch call made by the toutiao recommend command. When fetch itself rejects (DNS failure, connection reset, TLS error, timeout, aborted request), the original error message is embedded into a 'toutiao recommend request failed: ...' message so the CLI fails with a clear, command-scoped error.","triggerScenarios":"Calling the 'toutiao recommend' command when fetch() throws: no network connection, DNS resolution failure for www.toutiao.com, TLS handshake problems, request timeout, or request aborted.","commonSituations":"Running the CLI offline or behind a restrictive corporate proxy/firewall; intermittent network drops; Toutiao blocking or resetting connections from datacenter IPs; DNS misconfiguration; IPv6 issues.","solutions":["Check basic connectivity (curl -I https://www.toutiao.com) to confirm the network can reach the host.","If behind a proxy, set HTTPS_PROXY/HTTP_PROXY environment variables so fetch can route through it.","Retry with backoff — transient resets and timeouts often resolve on a second attempt.","Inspect the embedded error.message in the thrown error to identify the root cause (DNS vs TLS vs timeout)."],"exampleFix":"// before\nawait recommend({ category: 'tech' });\n// after\ntry {\n  await recommend({ category: 'tech' });\n} catch (e) {\n  if (String(e.message).includes('request failed')) {\n    console.error('Network issue reaching toutiao.com:', e.message);\n    // retry or fall back\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":"// quick reachability probe before the call\nconst ok = await fetch('https://www.toutiao.com/', { method: 'HEAD' })\n  .then(r => r.ok, () => false);\nif (!ok) throw new Error('toutiao.com unreachable; check network/proxy');","typeGuard":null,"tryCatchPattern":"try {\n  const items = await recommend({ category });\n} catch (e) {\n  if (String(e.message).startsWith('toutiao recommend request failed')) {\n    // transport-level failure: retry with backoff\n    await new Promise(r => setTimeout(r, 2000));\n    return recommend({ category });\n  }\n  throw e;\n}","preventionTips":["Verify DNS/proxy reachability to www.toutiao.com before running batch jobs.","Set HTTPS_PROXY when operating behind a corporate proxy.","Implement exponential backoff for transient transport errors.","Respect resiliency: avoid long unattended loops without failure handling."],"tags":["network","http","fetch-failure","cli"],"backgroundTag":"fetch-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}