{"record":{"id":"e5433285c32de043","repo":"denoland/deno","slug":"the-status-provided-init-status-is-not-equal","errorCode":null,"errorMessage":"The status provided (${init.status}) is not equal to 101 and outside the range [200, 599]","messagePattern":"The status provided \\((.+?)\\) is not equal to 101 and outside the range \\[200, 599\\]","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/23_response.js","lineNumber":518,"sourceCode":"  return resp;\n}\n\n/**\n * https://fetch.spec.whatwg.org#initialize-a-response\n * @param {Response} response\n * @param {ResponseInit} init\n * @param {{ body: fetchBody.InnerBody, contentType: string | null } | null} bodyWithType\n */\nfunction initializeAResponse(\n  response,\n  init,\n  bodyWithType,\n  prefix,\n  context,\n) {\n  // 1.\n  if ((init.status < 200 || init.status > 599) && init.status != 101) {\n    throw new RangeError(\n      `The status provided (${init.status}) is not equal to 101 and outside the range [200, 599]`,\n    );\n  }\n\n  // 2.\n  if (\n    init.statusText &&\n    RegExpPrototypeExec(REASON_PHRASE_RE, init.statusText) === null\n  ) {\n    throw new TypeError(\n      `Invalid status text: \"${init.statusText}\"`,\n    );\n  }\n\n  // 3.\n  response[_response].status = init.status;\n\n  // 4.","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/fetch/23_response.js#L500-L536","documentation":"initializeAResponse enforces the spec rule that a Response status is either 101 or within [200, 599]; anything else throws RangeError naming the offending value. This runs for new Response(...), Response.json(), and Response.redirect()-family constructors, before any body handling.","triggerScenarios":"new Response(body, { status: 199 }), { status: 600 }, { status: 102 }, or a status computed from arithmetic that lands outside the range (e.g. statusCode + 1).","commonSituations":"Forwarding upstream status codes that were transformed incorrectly, off-by-one math on status codes, mapping internal error codes (e.g. 1200, 7000) directly into Response statuses.","solutions":["Clamp or validate: use a status in 200-599 (or exactly 101) — for errors use 500","Check Number.isInteger(status) && ((status >= 200 && status <= 599) || status === 101) before constructing","Map custom application codes into the body/headers, not the HTTP status field"],"exampleFix":"// before\nreturn new Response(body, { status: upstreamCode + 1 }); // could be 600\n\n// after\nconst status = upstreamCode >= 200 && upstreamCode <= 599 ? upstreamCode : 502;\nreturn new Response(body, { status });","handlingStrategy":"type-guard","validationCode":"function sanitizeStatus(status, fallback = 500) {\n  const n = Number(status);\n  return Number.isInteger(n) && ((n >= 200 && n <= 599) || n === 101) ? n : fallback;\n}","typeGuard":"/** @param {unknown} s */\nfunction isValidResponseStatus(s) {\n  const n = Number(s);\n  return Number.isInteger(n) && ((n >= 200 && n <= 599) || n === 101);\n}","tryCatchPattern":null,"preventionTips":["Clamp externally sourced status codes to 200-599 (or 101) before Response construction","Put application error codes in the body, not the status field","Add a unit test over the boundaries (101, 199, 200, 599, 600) for response builders"],"tags":["fetch","response","status-code","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}