Skip to main content
Go to Latest
class HttpError
extends Error
Re-export
import { HttpError } from "https://deno.land/x/udibo_react_app@0.1.2/app_server.tsx";

An error for an HTTP request.

Constructors

new
HttpError(
status?: number,
message?: string,
options?: HttpErrorOptions & T,
)
new
HttpError(status?: number, options?: HttpErrorOptions & T)
new
HttpError(message?: string, options?: HttpErrorOptions & T)
new
HttpError(options?: HttpErrorOptions & T)
new
HttpError(
statusOrMessageOrOptions?: number | string | (HttpErrorOptions & T),
messageOrOptions?: string | (HttpErrorOptions & T),
options?: HttpErrorOptions & T,
)

Type Parameters

optional
T extends Record<string, unknown> = Record<string, unknown>

Properties

data: T

Other data associated with the error.

expose: boolean

Determines if the error should be exposed in the response. Defaults to true for client error statuses and false for server error statuses.

status: number

The HTTP status associated with the error. Must be a client or server error status. Defaults to 500.

Static Methods

from<T extends Record<string, unknown> = Record<string, unknown>>(error: HttpError<T> | Error | unknown): HttpError<T>

Converts any HttpError like objects into an HttpError. If the object is already an instance of HttpError, it will be returned as is.

json<T extends Record<string, unknown> = Record<string, unknown>>(error: HttpError<T> | Error | unknown): HttpErrorOptions & T

Converts an HttpError to an options object that can be used to re-create it. The message will only be included if the error should be exposed.

const error = new HttpError(400, "Invalid id");
const options = HttpError.json(error);
const copy = new HttpError(options);