import { VALIDATION_ERRORS } from '../../../db/enums' interface ValidationErrors { [key: string]: { properties: { message: string }; kind: string } } function getDefinedValidationMessage(kind: string) { switch (kind) { case VALIDATION_ERRORS.AT_LEAST_ONE_DAY_BOOKED: return 'Mindestens ein angefragter Tag ist nicht mehr verfügbar' default: return null } } export class ValidationError extends Error { private errors: ValidationErrors constructor(errors: ValidationErrors) { super() if (Error.captureStackTrace) { Error.captureStackTrace(this, ValidationError) } this.name = this.constructor.name this.errors = errors } get message() { return Object.entries<{ properties: { message: string }; kind: string }>( this.errors ) .map(([_key, value]) => { const validationMessage = getDefinedValidationMessage(value.kind) return validationMessage || `${value?.properties?.message}` }) .join(',') } }