jackwener/OpenCLI · error · CommandExecutionError

autohome ${contextHint} HTTP ${resp.status}

Error message

autohome ${contextHint} HTTP ${resp.status}

What it means

ahFetch() throws this CommandExecutionError when the server responded but with a non-2xx status. The context hint identifies which autohome page failed; the status code distinguishes 403 (bot-blocking), 404 (bad id/url), 429 (rate limit), 5xx (server-side) etc.

Source

Thrown at clis/autohome/utils.js:140

    return value;
}

/** Fetch an Autohome page as text. The grade + koubei pages are UTF-8. */
export async function ahFetch(url, contextHint) {
    let resp;
    try {
        resp = await fetch(url, {
            headers: {
                'User-Agent': UA,
                Referer: `${AH_BASE}/`,
                'Accept-Language': 'zh-CN,zh;q=0.9',
            },
        });
    } catch (err) {
        throw new CommandExecutionError(`autohome ${contextHint} network error: ${err?.message || err}`);
    }
    if (!resp.ok) {
        throw new CommandExecutionError(`autohome ${contextHint} HTTP ${resp.status}`);
    }
    return resp.text();
}

/** Extract __NEXT_DATA__ pageProps from a koubei page (pure, testable). */
export function extractPageProps(html) {
    const m = String(html || '').match(/<script id="__NEXT_DATA__"[^>]*>([\s\S]*?)<\/script>/);
    if (!m) return null;
    try {
        const data = JSON.parse(m[1]);
        return (data && data.props && data.props.pageProps) || null;
    } catch {
        return null;
    }
}

export { ArgumentError, CommandExecutionError, EmptyResultError };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the status: 404 means the id/URL is wrong — verify the series id; 403/429 means throttling/bot detection — slow down, add delays, use better headers/cookies
  2. Retry with exponential backoff for 5xx
  3. Confirm the URL is current (autohome may have changed page paths)

Example fix

// before
for (const id of ids) await ahFetch(url(id), 'grade');
// after
for (const id of ids) {
  await ahFetch(url(id), 'grade');
  await sleep(1500); // avoid 403/429
}
Defensive patterns

Strategy: try-catch

Validate before calling

const resp = await fetch(url, { method: 'HEAD' });
if (resp.status === 404) throw new Error('Series page does not exist: ' + url);
if (resp.status === 403 || resp.status === 429) throw new Error('Throttled by autohome');

Try / catch

try {
  const html = await ahFetch(url, 'grade');
} catch (err) {
  const m = /HTTP (\d+)/.exec(err.message || '');
  if (m) {
    const status = Number(m[1]);
    if (status === 404) throw new Error('Invalid series id/url');
    if (status === 403 || status === 429) await sleep(backoff(attempt++));
    else if (status >= 500) await sleep(backoff(attempt++));
    return fetchWithRetry(url, attempt);
  }
  throw err;
}

Prevention

When it happens

Trigger: Fetching a page with an invalid/deleted series id (404); autohome returning 403/429 to non-browser-like or too-frequent requests; transient 5xx outages.

Common situations: Scraping in a tight loop without delays; expired or geo-blocked pages; autohome WAF challenging the client.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/d0ca348984589834. Report an issue: GitHub.