{"record":{"id":"12fbfd441aaab1f6","repo":"jackwener/OpenCLI","slug":"rest-countries-returned-404-for-url","errorCode":null,"errorMessage":"REST Countries returned 404 for ${url}.","messagePattern":"REST Countries returned 404 for (.+?)\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":404,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":64,"sourceCode":"            `Allowed regions: ${[...REST_COUNTRIES_REGIONS].join(', ')}.`,\n        );\n    }\n    return raw;\n}\n\nexport async function restCountriesFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that restcountries.com is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `REST Countries returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(`${label} returned HTTP 429 (rate limited)`);\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);\n    }\n    let body;\n    try {\n        body = await resp.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    return body;\n}\n\n/** Convert REST Countries' `{cur: {name, symbol}}` map to a comma-joined list. */","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L46-L82","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the queried name/value and try the official current English name.","Inspect the URL in the error message and open it in a browser to confirm the 404.","Handle it as 'no match' in your app (catch EmptyResultError) rather than a crash.","Consider the codes or translation endpoints for alternative lookups."],"exampleFix":"// before\nawait countryCommand({ name: 'Burma' });\n// after\nawait countryCommand({ name: 'Myanmar' }); // current official name","handlingStrategy":"try-catch","validationCode":"// no reliable pre-call validation: existence is only knowable via the API;\n// sanitize the name at least\nconst safeName = encodeURIComponent(String(name ?? '').trim());\nif (!safeName) throw new Error('name required');","typeGuard":null,"tryCatchPattern":"try {\n  const countries = await countryCommand({ name });\n} catch (err) {\n  if (err instanceof EmptyResultError) {\n    // 404 from upstream = no such country; show 'not found' to the user\n  } else {\n    throw err;\n  }\n}","preventionTips":["Use current official country names (watch renames like Burma → Myanmar).","URL-encode user input before it reaches the command.","Treat EmptyResultError with a 404 message as 'not found', not a bug.","Keep an alias table for common informal/historical names."],"tags":["http-404","rest-countries","not-found","api"],"backgroundTag":"http-404-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}