{"record":{"id":"f80f4f0b7e56a615","repo":"sveltejs/kit","slug":"invalid-status-code","errorCode":null,"errorMessage":"Invalid status code","messagePattern":"Invalid status code","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/exports/index.js","lineNumber":131,"sourceCode":" * Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.\n *\n * Most common status codes:\n *  * `303 See Other`: redirect as a GET request (often used after a form POST request)\n *  * `307 Temporary Redirect`: redirect will keep the request method\n *  * `308 Permanent Redirect`: redirect will keep the request method, SEO will be transferred to the new page\n *\n * [See all redirect status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages)\n *\n * @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number)} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.\n * @param {string | URL} location The location to redirect to.\n * @param {{ external?: boolean | string[] }} [options] To redirect to an external URL, you must pass `{ external: true }` to allow any external URL except `javascript:` URLs, or `{ external: [...] }` with an allowlist of permitted origins.\n * @throws {import('./public.js').Redirect} This error instructs SvelteKit to redirect to the specified location.\n * @throws {Error} If the provided status is invalid, the location cannot be used as a header value, or the location is an external URL without permission.\n * @return {never}\n */\nexport function redirect(status, location, options) {\n\tif ((!BROWSER || DEV) && (isNaN(status) || status < 300 || status > 308)) {\n\t\tthrow new Error('Invalid status code');\n\t}\n\n\tconst href = location.toString();\n\tvalidate_redirect_location(href, options);\n\n\tthrow new Redirect(\n\t\t// @ts-ignore\n\t\tstatus,\n\t\thref\n\t);\n}\n\n/**\n * Checks whether this is a redirect thrown by {@link redirect}.\n * @param {unknown} e The object to check.\n * @return {e is import('./public.js').Redirect}\n */\nexport function isRedirect(e) {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/exports/index.js#L113-L149","documentation":"`redirect()` validates its status argument before constructing a `Redirect` object. SvelteKit requires redirect statuses to be in the 300–308 range; anything else (NaN, below 300, above 308) cannot be used as an HTTP redirect, so the library throws immediately in dev or on the server. This check is skipped in a production browser build since the status was already validated server-side.","triggerScenarios":"Calling `redirect(200, '/other')`, `redirect(404, '/missing')`, `redirect(0, ...)`, or passing a non-numeric string/variable that coerces to NaN. Also calling redirect with a variable status computed at runtime that falls outside 300–308.","commonSituations":"Confusing `redirect` with `error()` and using 404/500 statuses; using 301/302 which are fine but using 200 or 299 by mistake; passing `event.url.searchParams.get('status')` (a string) directly, yielding NaN.","solutions":["Change the status to a valid redirect code: 300–308 (typically 302, 303, 307, or 308).","If you meant to signal a missing page or error, use `error(404, ...)` instead of `redirect`.","Parse string inputs with `Number(status)` and validate `Number.isInteger(status) && status >= 300 && status <= 308` before calling.","For client-side navigation within a component, consider `goto()` instead of a raw redirect."],"exampleFix":"// before\nredirect(response.status, '/login');\n// after\nredirect(response.status >= 300 && response.status <= 308 ? response.status : 302, '/login');","handlingStrategy":"validation","validationCode":"function isValidRedirectStatus(s) {\n  return Number.isInteger(s) && s >= 300 && s <= 308;\n}\nif (!isValidRedirectStatus(status)) status = 302;","typeGuard":"const isRedirectStatus = (s) => typeof s === 'number' && Number.isInteger(s) && s >= 300 && s <= 308;","tryCatchPattern":"try {\n  redirect(status, location);\n} catch (e) {\n  if (e.message === 'Invalid status code') redirect(302, location);\n  else throw e;\n}","preventionTips":["Memorize the valid range: 300–308 only.","Use error() for 4xx/5xx outcomes, redirect() for navigation.","Coerce and validate any status coming from config, DB, or query strings.","Prefer named constants (302, 303, 307, 308) over arbitrary numbers."],"tags":["redirect","http-status","validation","sveltekit"],"backgroundTag":"invalid-redirect-status","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}