{"record":{"id":"7d86ebd4390adfd1","repo":"jackwener/OpenCLI","slug":"label-returned-http-resp-status-7d86eb","errorCode":null,"errorMessage":"${label} returned HTTP ${resp.status}","messagePattern":"(.+?) returned HTTP (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/tvmaze/utils.js","lineNumber":61,"sourceCode":"        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 api.tvmaze.com is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `TVmaze returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'TVmaze caps unauthenticated traffic at ~20 req/10s; wait a few seconds and retry.',\n        );\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\nconst HTML_ENTITY_MAP = {\n    amp: '&',\n    lt: '<',\n    gt: '>',\n    quot: '\"',\n    apos: \"'\",\n    nbsp: ' ',","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tvmaze/utils.js#L43-L79","documentation":"tvmazeFetch wraps every HTTP call to the TVmaze REST API. When a response arrives with a non-ok status that is not the specially-handled 429 case, it throws a CommandExecutionError embedding the label (e.g. 'search' or 'show') and the HTTP status code. This surfaces network/API failures like 404 (unknown show id), 400, or 5xx as a user-facing command error.","triggerScenarios":"The list or show commands call tvmazeFetch and api.tvmaze.com responds with an HTTP status other than 200 and other than 429 — e.g. 404 for an invalid show id path, 400 for a malformed query, or 5xx server errors.","commonSituations":"Typing a wrong TVmaze show id (404), typos in search terms producing unexpected endpoints, transient TVmaze server incidents (5xx), or a proxy/firewall returning error pages.","solutions":["Check the status code in the message: 404 usually means the show id or endpoint path is wrong — verify the id at tvmaze.com/shows/<id>","Retry after a short wait for 5xx statuses; TVmaze may be having an incident","Confirm the request URL is a valid https://api.tvmaze.com endpoint","For 429s see the separate rate-limit message with explicit guidance"],"exampleFix":"// before\nawait tvmazeFetch(`${TVMAZE_BASE}/shows/${rawId}`, 'show');\n// after\nconst id = requireShowId(rawId); // validates before hitting the API\nawait tvmazeFetch(`${TVMAZE_BASE}/shows/${id}`, 'show');","handlingStrategy":"retry","validationCode":"const id = requireShowId(rawId); // validate inputs before calling tvmazeFetch\nif (!Number.isInteger(id) || id <= 0) throw new Error('invalid show id');","typeGuard":"function isHttpResponseOk(resp) { return typeof resp.status === 'number' && resp.status >= 200 && resp.status < 300; }","tryCatchPattern":"try {\n  const data = await tvmazeFetch(url, 'show');\n} catch (err) {\n  const m = /HTTP (\\d{3})/.exec(err.message);\n  if (m && Number(m[1]) >= 500) return retryWithBackoff(url);\n  throw err; // 4xx: fix the request, don't retry\n}","preventionTips":["Validate ids/queries with requireShowId/requireString before fetching","Treat 4xx as caller errors and 5xx as retryable","Check https://www.tvmaze.com/api for endpoint validity","Watch for the explicit 429 message and back off"],"tags":["http","api","network"],"backgroundTag":"http-non-ok-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}