jackwener/OpenCLI · error · CommandExecutionError
${label} returned HTTP ${resp.status}
Error message
${label} returned HTTP ${resp.status} What it means
restCountriesFetch throws CommandExecutionError for any non-OK REST Countries response that is not 404 or 429, embedding the numeric HTTP status. It is a catch-all so unexpected server conditions (5xx, 3xx loops, unusual 4xx) are surfaced with their status code instead of failing silently.
Source
Thrown at clis/rest-countries/utils.js:70
export async function restCountriesFetch(url, label) {
let resp;
try {
resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
}
catch (err) {
throw new CommandExecutionError(
`${label} request failed: ${err?.message ?? err}`,
'Check that restcountries.com is reachable from this network.',
);
}
if (resp.status === 404) {
throw new EmptyResultError(label, `REST Countries returned 404 for ${url}.`);
}
if (resp.status === 429) {
throw new CommandExecutionError(`${label} returned HTTP 429 (rate limited)`);
}
if (!resp.ok) {
throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);
}
let body;
try {
body = await resp.json();
}
catch (err) {
throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);
}
return body;
}
/** Convert REST Countries' `{cur: {name, symbol}}` map to a comma-joined list. */
export function joinCurrencies(currencies) {
if (!currencies || typeof currencies !== 'object') return '';
return Object.entries(currencies)
.map(([code, info]) => {
const name = info && typeof info.name === 'string' ? info.name : '';
return name ? `${code} (${name})` : code;View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the command after a short wait — 5xx responses are often transient
- Check the REST Countries service status / try the URL in a browser
- If behind a proxy or firewall, test from an unrestricted network
- Report a bug if the status persists while the API works elsewhere
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try {
await restCountriesCommand(args);
} catch (e) {
const m = String(e.message).match(/HTTP (\d+)/);
if (m && Number(m[1]) >= 500) return await retryWithBackoff(args, 3);
throw e;
} Prevention
- Retry transient 5xx automatically with backoff
- Monitor restcountries.com status before large batch runs
- Avoid assuming every non-404 failure is your query's fault
- Log the status code for triage
When it happens
Trigger: The request to restcountries.com completes but resp.ok is false and the status is anything other than 404/429 — e.g. HTTP 500 during a REST Countries outage, 503 from a load balancer, or a gateway error from a CDN.
Common situations: REST Countries service downtime or maintenance; transient upstream/CDN failures; a proxy or corporate firewall returning an unexpected status; API version changes altering routing.
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/9739d1e82a59dd8e.
Report an issue: GitHub.