HttpError
An error that carries an HTTP status.
An error that carries an HTTP status. Throw it from a loader, a middleware, an API route or a server function: the framework answers with that status.
Client errors (4xx) expose their message by default, because they are written for the caller. Server errors (5xx) do not: their message is shown only in development.
Import#
ts
import { HttpError } from "@shadow-js/dusk";
Signature#
ts
class HttpError extends Error
Members#
| Name | Type | Description |
|---|---|---|
status |
readonly status: number |
The HTTP status, an integer from 400 to 599. |
expose |
readonly expose: boolean |
Whether the message may be sent to the client in production. |
headers |
readonly headers: Headers |
Extra response headers. |
data |
readonly data: unknown |
Serializable detail for the client, if any. |
Examples#
ts
if (user === undefined) throw new HttpError(401, "Sign in first", { headers: { "www-authenticate": "Bearer" } });