jackwener/OpenCLI · error · CliError
FETCH_ERROR
FETCH_ERROR
Error message
Wikipedia API HTTP ${resp.status} What it means
CliError with code FETCH_ERROR thrown by wikiFetch in clis/wikipedia/utils.js when the HTTP response from <lang>.wikipedia.org has a non-2xx status. Every wikipedia subcommand routes its requests through wikiFetch, so this surfaces for any endpoint-level HTTP failure (404, 403, 5xx).
Source
Thrown at clis/wikipedia/utils.js:19
/**
* Wikipedia adapter utilities.
*
* Uses the public MediaWiki REST API and Action API — no key required.
* REST API: https://en.wikipedia.org/api/rest_v1/
* Action API: https://en.wikipedia.org/w/api.php
*/
import { CliError } from '@jackwener/opencli/errors';
/** Maximum character length for article extract fields. */
export const EXTRACT_MAX_LEN = 300;
/** Maximum character length for short description fields. */
export const DESC_MAX_LEN = 80;
export async function wikiFetch(lang, path) {
const url = `https://${lang}.wikipedia.org${path}`;
const resp = await fetch(url, {
headers: { 'User-Agent': 'opencli/1.0 (https://github.com/jackwener/opencli)' },
});
if (!resp.ok) {
throw new CliError('FETCH_ERROR', `Wikipedia API HTTP ${resp.status}`, `Check your title or search term`);
}
return resp.json();
}
/** Map a WikiSummary API response to the standard output row. */
export function formatSummaryRow(data, lang) {
return {
title: data.title,
description: data.description ?? '-',
extract: (data.extract ?? '').slice(0, EXTRACT_MAX_LEN),
url: data.content_urls?.desktop?.page ?? `https://${lang}.wikipedia.org`,
};
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Check resp.status in the message: 403 usually means UA/rate-limit blocking — retry later or from another network; 404 means bad lang/title path; 5xx means upstream outage
- Verify the language code is a real Wikipedia edition
- Test connectivity: curl -I https://en.wikipedia.org/api/rest_v1/page/summary/Earth
- Check https://wikimediastatus.org for incidents and retry with backoff
Example fix
// before opencli wikipedia summary Earth --lang zz // after opencli wikipedia summary Earth --lang en
Defensive patterns
Strategy: retry
Validate before calling
if (!/^[a-z-]{2,8}$/.test(lang)) throw new Error(`invalid Wikipedia lang code: ${lang}`); Try / catch
try {
const rows = await run('wikipedia summary', [title, '--lang', lang]);
} catch (e) {
const m = /Wikipedia API HTTP (\d+)/.exec(e.message);
if (m) {
const status = Number(m[1]);
if (status >= 500 || status === 429) {
await sleep(2000);
return run('wikipedia summary', [title, '--lang', lang]);
}
console.error(`Wikipedia returned ${status}; check lang/title`);
} else throw e;
} Prevention
- Validate --lang codes before calling
- Treat 403 as UA/rate-limit blocking — back off
- Handle 5xx with exponential backoff retries
- Check network/proxy access to wikipedia.org
When it happens
Trigger: Any wikipedia subcommand hitting: invalid --lang producing DNS/404 failures, Wikipedia rate-limiting or blocking the default opencli/1.0 User-Agent (403), REST 404 for a bad title path, or upstream 5xx outages.
Common situations: Unsupported language codes, corporate proxies/firewalls blocking wikipedia.org, Wikimedia rate limits from shared IPs, transient Wikimedia outages.
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
- 12306 queryByTrainNo returned HTTP ${resp.status}
- 12306 queryByTrainNo returned non-JSON body
- 12306 ${endpoint} returned non-JSON body
- 1point3acres request failed: HTTP ${res.status} ${res.status
- ${label} returned HTTP ${resp.status}: ${summarizeApiError(p
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e483aeed66f5c252.
Report an issue: GitHub.