UNPKG

@pulzar/core

Version:

Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support

62 lines 2.18 kB
import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyError } from "fastify"; export interface ErrorResponse { error: string; message: string; statusCode: number; details?: Record<string, unknown>; requestId?: string; timestamp: string; } export interface FastifyErrorHandlerOptions { includeStack?: boolean; formatError?: (error: FastifyError) => ErrorResponse; customErrorCodes?: Record<string, number>; logErrors?: boolean; } export declare class FastifyErrorHandler { private options; constructor(options?: FastifyErrorHandlerOptions); private defaultErrorFormatter; /** * Fastify error handler */ handler(): (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => Promise<void>; /** * Register error handler with Fastify instance */ register(app: FastifyInstance): void; /** * Create validation error handler */ static validationErrorHandler(): (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => Promise<never>; /** * Create not found handler */ static notFoundHandler(): (request: FastifyRequest, reply: FastifyReply) => Promise<void>; } export declare function createFastifyErrorHandler(options?: FastifyErrorHandlerOptions): FastifyErrorHandler; export declare class ApiError extends Error { statusCode: number; code?: string | undefined; constructor(message: string, statusCode?: number, code?: string | undefined); } export declare class ValidationError extends ApiError { details?: any | undefined; constructor(message: string, details?: any | undefined); } export declare class AuthenticationError extends ApiError { constructor(message?: string); } export declare class AuthorizationError extends ApiError { constructor(message?: string); } export declare class NotFoundError extends ApiError { constructor(message?: string); } export declare class ConflictError extends ApiError { constructor(message?: string); } export declare class RateLimitError extends ApiError { constructor(message?: string); } //# sourceMappingURL=fastify-error-handler.d.ts.map