{"record":{"id":"9739d1e82a59dd8e","repo":"jackwener/OpenCLI","slug":"label-returned-http-resp-status-9739d1","errorCode":null,"errorMessage":"${label} returned HTTP ${resp.status}","messagePattern":"(.+?) returned HTTP (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/rest-countries/utils.js","lineNumber":70,"sourceCode":"export 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. */\nexport function joinCurrencies(currencies) {\n    if (!currencies || typeof currencies !== 'object') return '';\n    return Object.entries(currencies)\n        .map(([code, info]) => {\n            const name = info && typeof info.name === 'string' ? info.name : '';\n            return name ? `${code} (${name})` : code;","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"REST Countries service downtime or maintenance; transient upstream/CDN failures; a proxy or corporate firewall returning an unexpected status; API version changes altering routing.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await restCountriesCommand(args);\n} catch (e) {\n  const m = String(e.message).match(/HTTP (\\d+)/);\n  if (m && Number(m[1]) >= 500) return await retryWithBackoff(args, 3);\n  throw e;\n}","preventionTips":["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"],"tags":["http","network","http-5xx"],"backgroundTag":"unexpected-http-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}