/** * ValidationErrorCollection * * Esta clase representa un error de validación que agrega múltiples detalles de errores * en un formato estructurado. Es útil para manejar múltiples errores de validación * en una sola respuesta, permitiendo a los clientes entender qué campos fallaron y por qué. * * Ejemplo de uso: * * const errors: ValidationErrorDetail[] = [ * { path: "lines[1].unitPrice.amount", message: "Amount must be a positive number" }, * { path: "lines[1].unitPrice.scale", message: "Scale must be a non-negative integer" }, * ]; * const validationError = new ValidationErrorCollection(errors); * */ import { DomainError } from "./domain-error"; export interface ValidationErrorDetail { path?: string; // ejemplo: "lines[1].unitPrice.amount" message: string; // ejemplo: "Amount must be a positive number", value?: unknown; // valor inválido opcional } /** * Error de validación múltiple. Agrega varios fallos de una sola vez. */ export class ValidationErrorCollection extends DomainError { public readonly code = "VALIDATION" as const; public readonly details: ValidationErrorDetail[]; constructor(message: string, details: ValidationErrorDetail[], options?: ErrorOptions) { super(message, options); Object.setPrototypeOf(this, ValidationErrorCollection.prototype); this.name = "ValidationErrorCollection"; this.details = details; Object.freeze(this); } } export const isValidationErrorCollection = (e: unknown): e is ValidationErrorCollection => e instanceof ValidationErrorCollection;