{"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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/23_response.js#L500-L536","documentation":"initializeAResponse enforces the fetch-spec status rule: a Response status must be within [200, 599], or exactly 101 (Switching Protocols). Any other value — including 1xx (except 101), 3xx, 600+, negatives, or NaN after conversion — throws RangeError 'The status provided (N) is not equal to 101 and outside the range [200, 599]' at Response construction.","triggerScenarios":"new Response(body, { status: 302 }); { status: 102 }; { status: 600 }; { status: 0 } (e.g. forwarding a raw status of 0 from a transport failure); { status: -1 }.","commonSituations":"Forwarding a status code from another client that permits values fetch forbids (curl, Node http with status 100/3xx set directly); passing 0 as a sentinel; passing a redirect code to the Response constructor instead of Response.redirect.","solutions":["Choose a status in 200-599 (e.g. 200 for success, 502 for upstream failure)","For redirects use the static Response.redirect(url, 302) API, not new Response(..., { status: 302 })","Clamp/validate forwarded statuses: status = upstream >= 200 && upstream <= 599 ? upstream : 502"],"exampleFix":"// before\nnew Response(\"moved\", { status: 302 }); // throws RangeError\nnew Response(\"err\", { status: 0 }); // throws\n\n// after\nResponse.redirect(\"https://example.com/new\", 302); // redirects\nnew Response(\"err\", { status: 502 }); // sentinel mapped into range","handlingStrategy":"validation","validationCode":"function toFetchStatus(status) {\n  return status === 101 || (status >= 200 && status <= 599) ? status : 502;\n}\nnew Response(body, { status: toFetchStatus(upstreamStatus) });","typeGuard":"function isValidResponseStatus(s: number): boolean {\n  return s === 101 || (Number.isInteger(s) && s >= 200 && s <= 599);\n}","tryCatchPattern":"try {\n  return new Response(body, { status });\n} catch (err) {\n  if (err instanceof RangeError && err.message.includes(\"status provided\")) {\n    return new Response(body, { status: 502 }); // map out-of-range to Bad Gateway\n  }\n  throw err;\n}","preventionTips":["Clamp forwarded upstream statuses into 200-599 (usually to 502)","Use Response.redirect for 3xx instead of the constructor","Remember 101 is the only allowed 1xx status for a constructed Response"],"tags":["fetch","response","status-code","validation"],"backgroundTag":"invalid-http-status-code","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}