{"record":{"id":"cc742784d831cb1e","repo":"jackwener/OpenCLI","slug":"label-returned-http-resp-status-cc7427","errorCode":null,"errorMessage":"${label} returned HTTP ${resp.status}","messagePattern":"(.+?) returned HTTP (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/oeis/utils.js","lineNumber":64,"sourceCode":"export async function oeisFetch(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 oeis.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `OEIS 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/** Format OEIS' `number: 40` into the canonical zero-padded id `A000040`. */\nexport function formatId(number) {\n    if (typeof number !== 'number' || !Number.isInteger(number) || number < 0) return null;\n    return `A${String(number).padStart(6, '0')}`;\n}\n\n/** Take the first N comma-separated terms from OEIS' `data` string. */","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/oeis/utils.js#L46-L82","documentation":"After handling 404 and 429, oeisFetch checks resp.ok and throws this CommandExecutionError for any other non-2xx status (e.g. 500, 502, 503). The message includes the exact HTTP status and the resource label. This catches server-side or unexpected upstream errors.","triggerScenarios":"oeis.org returning 5xx during an outage or maintenance, an unexpected 403 from an edge/WAF rule, or any status other than 200/404/429.","commonSituations":"OEIS server downtime, transient gateway errors (502/503 from a reverse proxy), or an API endpoint changing and rejecting old request shapes.","solutions":["Retry later — 5xx usually indicates a server-side outage.","Check oeis.org in a browser to see if the site is up.","Inspect the status code in the message to decide whether to retry (5xx) or fix the request (4xx)."],"exampleFix":"// retry on transient status\ntry {\n  return await oeisFetch(url, label);\n} catch (e) {\n  if (String(e.message).includes('HTTP 5')) return await oeisFetch(url, label);\n  throw e;\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { return await oeisFetch(url, label); }\ncatch (e) {\n  const m = String(e.message).match(/HTTP (\\d+)/);\n  if (m && +m[1] >= 500) return await oeisFetch(url, label); // retry transient 5xx\n  throw e;\n}","preventionTips":["Retry 5xx responses with backoff; do not retry 4xx.","Check oeis.org status before large batch jobs.","Surface the exact status code from the message in your logs."],"tags":["http","server-error","fetch"],"backgroundTag":"http-server-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}