jackwener/OpenCLI · error · CommandExecutionError
toutiao recommend request failed: ${error?.message || error}
Error message
toutiao recommend request failed: ${error?.message || error} What it means
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.
Source
Thrown at clis/toutiao/recommend.js:49
{ name: 'category', type: 'string', default: '__all__', help: `频道 (${RECOMMEND_CATEGORIES.join(', ')})` },
{ name: 'limit', type: 'int', default: 20, help: '返回条数 (1-50)' },
],
columns: ['rank', 'group_id', 'title', 'abstract', 'source', 'tag', 'comments', 'published_at', 'url', 'image_url'],
func: async (kwargs) => {
const category = parseRecommendCategory(kwargs?.category, '__all__');
const limit = parseRecommendLimit(kwargs?.limit, 20);
const url = `${RECOMMEND_URL}?category=${encodeURIComponent(category)}`;
let resp;
try {
resp = await fetch(url, {
headers: {
'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',
Accept: 'application/json',
Referer: 'https://www.toutiao.com/',
},
});
} catch (error) {
throw new CommandExecutionError(`toutiao recommend request failed: ${error?.message || error}`);
}
if (!resp.ok) {
throw new CommandExecutionError(`toutiao recommend failed: HTTP ${resp.status}`);
}
let payload;
try {
payload = await resp.json();
} catch (error) {
throw new CommandExecutionError(`toutiao recommend returned malformed JSON: ${error?.message || error}`);
}
if (payload?.message && payload.message !== 'success') {
throw new CommandExecutionError(`toutiao recommend returned message=${payload.message}`);
}
if (!Array.isArray(payload?.data)) {
throw new CommandExecutionError('toutiao recommend returned a non-array data field');
}
const rows = payload.data.map(mapRecommendRow).filter(Boolean).slice(0, limit);
if (rows.length === 0) {View on GitHub (pinned to 49907e53dc)
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).
Example fix
// before
await recommend({ category: 'tech' });
// after
try {
await recommend({ category: 'tech' });
} catch (e) {
if (String(e.message).includes('request failed')) {
console.error('Network issue reaching toutiao.com:', e.message);
// retry or fall back
} else throw e;
} Defensive patterns
Strategy: retry
Validate before calling
// quick reachability probe before the call
const ok = await fetch('https://www.toutiao.com/', { method: 'HEAD' })
.then(r => r.ok, () => false);
if (!ok) throw new Error('toutiao.com unreachable; check network/proxy'); Try / catch
try {
const items = await recommend({ category });
} catch (e) {
if (String(e.message).startsWith('toutiao recommend request failed')) {
// transport-level failure: retry with backoff
await new Promise(r => setTimeout(r, 2000));
return recommend({ category });
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- `${label} returned malformed JSON: ${err?.message ?? err}`
- linux.do request failed: HTTP ${result.status ?? 'unknown'}
- mdn search request failed: ${err?.message ?? err}
- medium tag request failed: ${err?.message ?? err}
- HTTP ${result.httpStatus} from ${result.where}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/fb6c384472733d61.
Report an issue: GitHub.