{"record":{"id":"f38845ba58a6abfc","repo":"jackwener/OpenCLI","slug":"autohome-contexthint-network-error-err-mess","errorCode":null,"errorMessage":"autohome ${contextHint} network error: ${err?.message || err}","messagePattern":"autohome (.+?) network error: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/autohome/utils.js","lineNumber":137,"sourceCode":"    if (!value || typeof value !== 'object' || Array.isArray(value)) {\n        throw new CommandExecutionError(`${label} returned an unexpected payload shape; expected an object.`);\n    }\n    return value;\n}\n\n/** Fetch an Autohome page as text. The grade + koubei pages are UTF-8. */\nexport async function ahFetch(url, contextHint) {\n    let resp;\n    try {\n        resp = await fetch(url, {\n            headers: {\n                'User-Agent': UA,\n                Referer: `${AH_BASE}/`,\n                'Accept-Language': 'zh-CN,zh;q=0.9',\n            },\n        });\n    } catch (err) {\n        throw new CommandExecutionError(`autohome ${contextHint} network error: ${err?.message || err}`);\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`autohome ${contextHint} HTTP ${resp.status}`);\n    }\n    return resp.text();\n}\n\n/** Extract __NEXT_DATA__ pageProps from a koubei page (pure, testable). */\nexport function extractPageProps(html) {\n    const m = String(html || '').match(/<script id=\"__NEXT_DATA__\"[^>]*>([\\s\\S]*?)<\\/script>/);\n    if (!m) return null;\n    try {\n        const data = JSON.parse(m[1]);\n        return (data && data.props && data.props.pageProps) || null;\n    } catch {\n        return null;\n    }\n}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/autohome/utils.js#L119-L155","documentation":"ahFetch() wraps any network-level failure from its HTTP client into this CommandExecutionError, prefixing the request context (contextHint) and the underlying error message. It signals the autohome page could not be retrieved at the transport layer (before any HTTP status was read).","triggerScenarios":"DNS resolution failure, connection timeout/reset, TLS error, or proxy unreachability while fetching an autohome grade/koubei page.","commonSituations":"No internet or captive portal; corporate firewall/Great-Firewall blocking autohome domains; transient network flakiness; IPv6/DNS misconfiguration.","solutions":["Check basic connectivity (curl https://k.autohome.com.cn) and DNS","Retry with backoff — many failures are transient","Check proxy/firewall/VPN settings that may block autohome.com.cn domains"],"exampleFix":"// before\nconst html = await ahFetch(url, 'koubei');\n// after\nconst html = await withRetry(3, () => ahFetch(url, 'koubei'));","handlingStrategy":"retry","validationCode":"// pre-check connectivity\nconst online = await fetch('https://k.autohome.com.cn/', { method: 'HEAD' })\n  .then(() => true).catch(() => false);\nif (!online) throw new Error('No connectivity to autohome');","typeGuard":null,"tryCatchPattern":"try {\n  const html = await ahFetch(url, 'koubei');\n} catch (err) {\n  if (err instanceof CommandExecutionError && /network error/.test(err.message)) {\n    await sleep(backoff(attempt++));\n    return fetchWithRetry(url, attempt);\n  }\n  throw err;\n}","preventionTips":["Implement retry with exponential backoff for all autohome fetches","Check proxy/firewall settings if running in corporate/container environments","Fail fast with a connectivity check when offline"],"tags":["network","http","connectivity"],"backgroundTag":"connection-refused","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}