{"record":{"id":"fa0a8ff6467855bf","repo":"jackwener/OpenCLI","slug":"label-request-failed-err-message-err-fa0a8f","errorCode":null,"errorMessage":"${label} request failed: ${err?.message ?? err}","messagePattern":"(.+?) request failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"critical","filePath":"clis/rest-countries/utils.js","lineNumber":58,"sourceCode":"export function requireRegion(value) {\n    const raw = String(value ?? '').trim().toLowerCase();\n    if (!raw) throw new ArgumentError('rest-countries region is required (e.g. \"europe\", \"asia\")');\n    if (!REST_COUNTRIES_REGIONS.has(raw)) {\n        throw new ArgumentError(\n            `rest-countries region \"${value}\" is not recognised`,\n            `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) {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rest-countries/utils.js#L40-L76","documentation":"restCountriesFetch wraps the underlying fetch call and throws CommandExecutionError when the network request itself rejects (DNS failure, connection refused, TLS error, timeout). The message includes the command label and the underlying error message, plus a hint to check reachability of restcountries.com. This is a transport-level failure, not an HTTP error status.","triggerScenarios":"Calling any rest-countries command while restcountries.com is unreachable: no internet, DNS outage, corporate proxy/firewall blocking the domain, or Node lacking network access in a sandbox/CI environment.","commonSituations":"Running in an offline or air-gapped environment; CI runners without egress; DNS misconfiguration; VPN or firewall rules; IPv6 issues resolving the API host.","solutions":["Verify network connectivity (curl https://restcountries.com/v3.1/all).","Check DNS resolution of restcountries.com and any proxy settings (HTTP(S)_PROXY env vars).","Retry after transient outages; add backoff around the command.","Catch CommandExecutionError and surface a friendly offline message."],"exampleFix":"// before\nconst data = await countryCommand({ name: 'japan' });\n// after\nlet data;\ntry {\n  data = await countryCommand({ name: 'japan' });\n} catch (err) {\n  if (err instanceof CommandExecutionError && /request failed/.test(err.message)) {\n    data = await withRetry(() => countryCommand({ name: 'japan' }));\n  } else throw err;\n}","handlingStrategy":"retry","validationCode":"// check reachability before the call\nconst ok = await fetch('https://restcountries.com/v3.1/all?fields=name')\n  .then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('restcountries.com is not reachable');","typeGuard":null,"tryCatchPattern":"try {\n  const data = await countryCommand({ name });\n} catch (err) {\n  if (err instanceof CommandExecutionError && /request failed/.test(err.message)) {\n    // offline/DNS/proxy problem: retry with backoff or degrade gracefully\n  } else {\n    throw err;\n  }\n}","preventionTips":["Add retry with exponential backoff for transient network failures.","Set and verify HTTP(S)_PROXY in corporate/CI environments.","Health-check the API host before batch runs.","Cache previous responses to tolerate short outages."],"tags":["network","fetch","dns","rest-countries"],"backgroundTag":"network-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}