Skip to content

docs: links to http status codes #8480

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 1 commit into from
Jan 13, 2023
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/mean-pants-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

docs: links to http status codes
15 changes: 10 additions & 5 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ export type ActionResult<
* Creates an `HttpError` object with an HTTP status code and an optional message.
* This object, if thrown during request handling, will cause SvelteKit to
* return an error response without invoking `handleError`
* @param status The HTTP status code
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
*/
export function error(status: number, body: App.Error): HttpError;
Expand All @@ -1094,15 +1094,16 @@ export function error(
* The object returned by the [`error`](https://kit.svelte.dev/docs/modules#sveltejs-kit-error) function.
*/
export interface HttpError {
/** The [HTTP status code](https://httpstatusdogs.com), in the range 400-599 */
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
status: number;
/** The content of the error. */
body: App.Error;
}

/**
* Create a `Redirect` object. If thrown during request handling, SvelteKit will
* return a redirect response.
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
* @param location The location to redirect to.
*/
export function redirect(
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308,
Expand All @@ -1113,7 +1114,7 @@ export function redirect(
* The object returned by the [`redirect`](https://kit.svelte.dev/docs/modules#sveltejs-kit-redirect) function
*/
export interface Redirect {
/** The [HTTP status code](https://httpstatusdogs.com), in the range 300-308. */
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages), in the range 300-308. */
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
/** The location to redirect to. */
location: string;
Expand All @@ -1128,6 +1129,8 @@ export function json(data: any, init?: ResponseInit): Response;

/**
* Create an `ActionFailure` object.
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
* @param data Data associated with the failure (e.g. validation errors)
*/
export function fail<T extends Record<string, unknown> | undefined>(
status: number,
Expand All @@ -1139,7 +1142,9 @@ export function fail<T extends Record<string, unknown> | undefined>(
*/
export interface ActionFailure<T extends Record<string, unknown> | undefined = undefined>
extends UniqueInterface {
/** The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses), in the range 400-599. */
status: number;
/** Data associated with the failure (e.g. validation errors) */
data: T;
}

Expand Down