Skip to content

narrow down possible status codes for redirects to 300-308 #7615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-seas-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] narrow down possible status codes for redirects to 300-308
2 changes: 1 addition & 1 deletion packages/kit/src/exports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function error(status, message) {

/** @type {import('@sveltejs/kit').redirect} */
export function redirect(status, location) {
if (isNaN(status) || status < 300 || status > 399) {
if (isNaN(status) || status < 300 || status > 308) {
throw new Error('Invalid status code');
}

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export function error(status, message) {
/**
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
* return a redirect response.
* @param {number} status
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
* @param {string} location
*/
export function redirect(status, location) {
if (isNaN(status) || status < 300 || status > 399) {
if (isNaN(status) || status < 300 || status > 308) {
throw new Error('Invalid status code');
}

Expand Down
5 changes: 4 additions & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,10 @@ export function error(
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
* return a redirect response.
*/
export function redirect(status: number, location: string): Redirect;
export function redirect(
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
location: string
): Redirect;

/**
* Generates a JSON `Response` object from the supplied data.
Expand Down