@stacksjs/error-handling
Version:
Type safe error handling.
50 lines (49 loc) • 1.68 kB
TypeScript
import type { ErrorPageConfig, RequestContext, RoutingContext } from './error-page';
/**
* Create a new HTTP error handler
*/
export declare function createHttpErrorHandler(options?: {
isDevelopment?: boolean
config?: ErrorPageConfig
}): HttpErrorHandler;
/**
* Quick helper to render an error page for HTTP errors
*/
export declare function renderHttpError(error: Error, request?: Request, options?: {
status?: number
isDevelopment?: boolean
config?: ErrorPageConfig
}): Promise<Response>;
/**
* Express/Hono style error middleware
*/
export declare function errorMiddleware(options?: {
isDevelopment?: boolean
config?: ErrorPageConfig
}): void;
export declare class HttpError extends Error {
details?: unknown;
public status: number;
constructor(status: number, message: string, details?: unknown);
}
/**
* HTTP error handler with Ignition-style error pages
*/
export declare class HttpErrorHandler {
constructor(options?: {
isDevelopment?: boolean
config?: ErrorPageConfig
});
setRequest(request: Request | RequestContext): this;
setRouting(routing: RoutingContext): this;
addQuery(query: string, time?: number, connection?: string): this;
handle(error: Error, status?: number): Promise<Response>;
notFound(message?: string): Promise<Response>;
serverError(error: Error): Promise<Response>;
forbidden(message?: string): Promise<Response>;
unauthorized(message?: string): Promise<Response>;
badRequest(message?: string): Promise<Response>;
validationError(message?: string): Promise<Response>;
tooManyRequests(message?: string): Promise<Response>;
serviceUnavailable(message?: string): Promise<Response>;
}