{"record":{"id":"e483aeed66f5c252","repo":"jackwener/OpenCLI","slug":"fetch-error-e483ae","errorCode":"FETCH_ERROR","errorMessage":"Wikipedia API HTTP ${resp.status}","messagePattern":"Wikipedia API HTTP (.+?)","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/wikipedia/utils.js","lineNumber":19,"sourceCode":"/**\n * Wikipedia adapter utilities.\n *\n * Uses the public MediaWiki REST API and Action API — no key required.\n * REST API: https://en.wikipedia.org/api/rest_v1/\n * Action API: https://en.wikipedia.org/w/api.php\n */\nimport { CliError } from '@jackwener/opencli/errors';\n/** Maximum character length for article extract fields. */\nexport const EXTRACT_MAX_LEN = 300;\n/** Maximum character length for short description fields. */\nexport const DESC_MAX_LEN = 80;\nexport async function wikiFetch(lang, path) {\n    const url = `https://${lang}.wikipedia.org${path}`;\n    const resp = await fetch(url, {\n        headers: { 'User-Agent': 'opencli/1.0 (https://github.com/jackwener/opencli)' },\n    });\n    if (!resp.ok) {\n        throw new CliError('FETCH_ERROR', `Wikipedia API HTTP ${resp.status}`, `Check your title or search term`);\n    }\n    return resp.json();\n}\n/** Map a WikiSummary API response to the standard output row. */\nexport function formatSummaryRow(data, lang) {\n    return {\n        title: data.title,\n        description: data.description ?? '-',\n        extract: (data.extract ?? '').slice(0, EXTRACT_MAX_LEN),\n        url: data.content_urls?.desktop?.page ?? `https://${lang}.wikipedia.org`,\n    };\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/utils.js#L1-L32","documentation":"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).","triggerScenarios":"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.","commonSituations":"Unsupported language codes, corporate proxies/firewalls blocking wikipedia.org, Wikimedia rate limits from shared IPs, transient Wikimedia outages.","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"],"exampleFix":"// before\nopencli wikipedia summary Earth --lang zz\n// after\nopencli wikipedia summary Earth --lang en","handlingStrategy":"retry","validationCode":"if (!/^[a-z-]{2,8}$/.test(lang)) throw new Error(`invalid Wikipedia lang code: ${lang}`);","typeGuard":null,"tryCatchPattern":"try {\n  const rows = await run('wikipedia summary', [title, '--lang', lang]);\n} catch (e) {\n  const m = /Wikipedia API HTTP (\\d+)/.exec(e.message);\n  if (m) {\n    const status = Number(m[1]);\n    if (status >= 500 || status === 429) {\n      await sleep(2000);\n      return run('wikipedia summary', [title, '--lang', lang]);\n    }\n    console.error(`Wikipedia returned ${status}; check lang/title`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["network","http","wikipedia"],"backgroundTag":"http-error-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}