@thalorlabs/errors
Version:
Enhanced exception handling system for TypeScript applications with comprehensive error classes and debugging capabilities
26 lines (25 loc) • 942 B
TypeScript
/**
* Base error class for all ThalorLabs error types with standardized error handling.
*
* Provides common error properties, HTTP status mapping, and serialization methods.
* All custom error classes should extend this base class for consistent error handling.
*
* @example
* throw new CustomError(400, 'Invalid request data', 'req-123', { field: 'email' });
*
* // In error handling middleware
* const errorResponse = customError.getErrorResponse();
* res.status(customError.statusCode).json(errorResponse);
*/
export declare class CustomError extends Error {
statusCode: number;
status: string;
timestamp: Date;
requestId?: string;
context?: Record<string, any>;
constructor(statusCode: number, message: string, requestId?: string, context?: Record<string, any>);
getStatusText(): string;
toJSON(): Record<string, any>;
getErrorResponse(): Record<string, any>;
}
export default CustomError;