UNPKG

@travetto/schema

Version:

Data type registry for runtime validation, reflection and binding.

27 lines (24 loc) 938 B
import { type Class, AppError } from '@travetto/runtime'; import type { ValidationError } from './types.ts'; /** * Validation results error. * * Hold all the validation errors for a given schema validation */ export class ValidationResultError extends AppError<{ errors: ValidationError[] }> { constructor(errors: ValidationError[]) { super('Validation errors have occurred', { category: 'data', details: { errors } }); } } /** * Represents when a requested objects's type doesn't match the class being used to request. * Primarily applies to polymorphic types */ export class TypeMismatchError extends AppError { constructor(cls: Class | string, type: string) { super(`Expected ${typeof cls === 'string' ? cls : cls.name} but found ${type}`, { category: 'data' }); } } export function isValidationError(error: unknown): error is ValidationError { return !!error && error instanceof Error && 'path' in error; }