Skip to content

DX improvement: narrow down possible status codes for the redirect helper #7614

Closed
@ivanhofer

Description

@ivanhofer

Describe the problem

The current implementation throws an error if the statuscode passed to redirect is smaller than 300 or bigger than 399 which is already a good indicator what kind of status codes are supported.

But actually the range is way smaller: from 300 to 308
https://www.rfc-editor.org/rfc/rfc9110#name-redirection-3xx

With all other status codes the browser will not know what to do.

Another smaller issue is, that the TypeScript type is set to number, which is correct, but it could be narrowed down to the actual values that are supported.
Background: a while ago someone threw a 401 redirect in our codebase and we didn't spot the issue immediately.

Describe the proposed solution

Narrowing down the amount of status code allowed for the redirect helper function to the official ones ranging from 300 to 308

  • for runtime code
  • and also at the TypeScript level

While testing a few things it seems that 305 and 306 are ignored by firefox and chrome. 300 gets ignored by chrome. So maybe also removing status codes that will not work makes sense? (306 is officialy marked as "unused")

Opening this issue for discussion reasons. I can also create the PR if it helps you :)

Alternatives considered

Leaving as it is

Importance

would make my life easier

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions