denoland/deno · error · RangeError

The status provided ( ) is not equal to 101 and outside the…

Error message

The status provided (${init.status}) is not equal to 101 and outside the range [200, 599]

What it means

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.

Solutions

  1. Choose a status in 200-599 (e.g. 200 for success, 502 for upstream failure)
  2. For redirects use the static Response.redirect(url, 302) API, not new Response(..., { status: 302 })
  3. Clamp/validate forwarded statuses: status = upstream >= 200 && upstream <= 599 ? upstream : 502

Example fix

// before
new Response("moved", { status: 302 }); // throws RangeError
new Response("err", { status: 0 }); // throws

// after
Response.redirect("https://example.com/new", 302); // redirects
new Response("err", { status: 502 }); // sentinel mapped into range
Defensive patterns

Strategy: validation

Validate before calling

function toFetchStatus(status) {
  return status === 101 || (status >= 200 && status <= 599) ? status : 502;
}
new Response(body, { status: toFetchStatus(upstreamStatus) });

Type guard

function isValidResponseStatus(s: number): boolean {
  return s === 101 || (Number.isInteger(s) && s >= 200 && s <= 599);
}

Try / catch

try {
  return new Response(body, { status });
} catch (err) {
  if (err instanceof RangeError && err.message.includes("status provided")) {
    return new Response(body, { status: 502 }); // map out-of-range to Bad Gateway
  }
  throw err;
}

Prevention

When it happens

Trigger: 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 }.

Common situations: 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.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/e5433285c32de043. Report an issue: GitHub.

Appendix: source

Thrown at ext/fetch/23_response.js:518

  return resp;
}

/**
 * https://fetch.spec.whatwg.org#initialize-a-response
 * @param {Response} response
 * @param {ResponseInit} init
 * @param {{ body: fetchBody.InnerBody, contentType: string | null } | null} bodyWithType
 */
function initializeAResponse(
  response,
  init,
  bodyWithType,
  prefix,
  context,
) {
  // 1.
  if ((init.status < 200 || init.status > 599) && init.status != 101) {
    throw new RangeError(
      `The status provided (${init.status}) is not equal to 101 and outside the range [200, 599]`,
    );
  }

  // 2.
  if (
    init.statusText &&
    RegExpPrototypeExec(REASON_PHRASE_RE, init.statusText) === null
  ) {
    throw new TypeError(
      `Invalid status text: "${init.statusText}"`,
    );
  }

  // 3.
  response[_response].status = init.status;

  // 4.

View on GitHub (pinned to 9ad36f7a2c)