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

  1. Retry the command after a short wait — 5xx responses are often transient
  2. Check the REST Countries service status / try the URL in a browser
  3. If behind a proxy or firewall, test from an unrestricted network
  4. 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

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


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