UNPKG

@thalorlabs/errors

Version:

Enhanced exception handling system for TypeScript applications with comprehensive error classes and debugging capabilities

35 lines (34 loc) 1.25 kB
import CustomError from './CustomError'; /** * Error for input validation failures with detailed field-level information. * * Used when request data fails validation with specific field errors. * Provides structured error information for API responses with HTTP 422 status. * * @example * throw new ValidationError('Validation failed', [ * { field: 'email', message: 'Invalid email format', value: 'invalid-email' }, * { field: 'password', message: 'Password too short', value: '123' } * ], 'req-123'); * * // Add more validation errors dynamically * validationError.addValidationError('age', 'Must be 18 or older', 16); */ export declare class ValidationError extends CustomError { validationErrors: Array<{ field: string; message: string; value?: any; code?: string; }>; constructor(message?: string, validationErrors?: Array<{ field: string; message: string; value?: any; code?: string; }>, requestId?: string, context?: Record<string, any>); addValidationError(field: string, message: string, value?: any, code?: string): void; getErrorResponse(): Record<string, any>; toJSON(): Record<string, any>; } export default ValidationError;