jackwener/OpenCLI · error · EmptyResultError

REST Countries returned 404 for ${url}.

Error message

REST Countries returned 404 for ${url}.

What it means

restCountriesFetch throws EmptyResultError when the REST Countries API responds with HTTP 404, meaning the requested resource (e.g. a country name) does not exist upstream. It converts the bare status into a labeled error including the exact URL queried, so callers can distinguish 'not found' from other HTTP failures. Note 404 is treated as an empty result, not a hard failure.

Source

Thrown at clis/rest-countries/utils.js:64

            `Allowed regions: ${[...REST_COUNTRIES_REGIONS].join(', ')}.`,
        );
    }
    return raw;
}

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. */

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check the queried name/value and try the official current English name.
  2. Inspect the URL in the error message and open it in a browser to confirm the 404.
  3. Handle it as 'no match' in your app (catch EmptyResultError) rather than a crash.
  4. Consider the codes or translation endpoints for alternative lookups.

Example fix

// before
await countryCommand({ name: 'Burma' });
// after
await countryCommand({ name: 'Myanmar' }); // current official name
Defensive patterns

Strategy: try-catch

Validate before calling

// no reliable pre-call validation: existence is only knowable via the API;
// sanitize the name at least
const safeName = encodeURIComponent(String(name ?? '').trim());
if (!safeName) throw new Error('name required');

Try / catch

try {
  const countries = await countryCommand({ name });
} catch (err) {
  if (err instanceof EmptyResultError) {
    // 404 from upstream = no such country; show 'not found' to the user
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Calling the rest-countries country command with a name whose /v3.1/name/{name} URL 404s (no match at the API), or any command building a URL path the API does not recognize; caught at `if (resp.status === 404)` in clis/rest-countries/utils.js:64.

Common situations: Misspelled or obsolete country names ('Burma' vs 'Myanmar' naming changes); URL-encoding issues; using an endpoint path the v3.1 API removed; typos in programmatic inputs.

Related errors


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