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

50 lines 2.39 kB
import { Request, Response, NextFunction } from "express"; export interface ErrorResponse { error: string; message: string; statusCode: number; details?: Record<string, unknown>; requestId?: string; timestamp: string; } export interface ErrorHandlerOptions { includeStack?: boolean; customErrorCodes?: Record<string, number>; formatError?: (error: Error) => ErrorResponse; } export declare class ApiError extends Error { statusCode: number; details?: Record<string, unknown>; constructor(message: string, statusCode?: number, details?: Record<string, unknown>); } export declare class ErrorHandler { private options; constructor(options?: ErrorHandlerOptions); /** * Express error handling middleware */ middleware(): (error: Error, req: Request, res: Response, next: NextFunction) => void; /** * Create formatted error response */ formatError(error: Error): ErrorResponse; } export declare const errorHandler: ErrorHandler; export declare const ApiErrors: { BadRequest: (message?: string, details?: Record<string, unknown>) => ApiError; Unauthorized: (message?: string, details?: Record<string, unknown>) => ApiError; Forbidden: (message?: string, details?: Record<string, unknown>) => ApiError; NotFound: (message?: string, details?: Record<string, unknown>) => ApiError; MethodNotAllowed: (message?: string, details?: Record<string, unknown>) => ApiError; Conflict: (message?: string, details?: Record<string, unknown>) => ApiError; UnprocessableEntity: (message?: string, details?: Record<string, unknown>) => ApiError; TooManyRequests: (message?: string, details?: Record<string, unknown>) => ApiError; InternalServerError: (message?: string, details?: Record<string, unknown>) => ApiError; NotImplemented: (message?: string, details?: Record<string, unknown>) => ApiError; ServiceUnavailable: (message?: string, details?: Record<string, unknown>) => ApiError; }; export declare function isApiError(error: unknown): error is ApiError; export declare function createErrorHandler(options?: ErrorHandlerOptions): (error: Error, req: Request, res: Response, next: NextFunction) => void; declare const _default: (error: Error, req: Request, res: Response, next: NextFunction) => void; export default _default; //# sourceMappingURL=errorHandler.d.ts.map