Skip to content

Commit

Permalink
docs: links to http status codes (#8480)
Browse files Browse the repository at this point in the history
closes #8264
  • Loading branch information
dummdidumm authored Jan 13, 2023
1 parent 130abe4 commit b6ca02a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit b6ca02a

Please sign in to comment.