data-transfer-object
Version:
Data Transfer Object class built on `class-validator`.
38 lines (37 loc) • 1.59 kB
TypeScript
import { ValidationError } from 'class-validator';
import { ValidationErrorMap } from './validation-error-map';
export declare type ValidationErrorHandler = (errors: ValidationError[]) => void;
export declare type ValidationErrorMapHandler = (errorMap: ValidationErrorMap) => void;
export interface ValidationErrorHandlerOptions {
/**
* By default, errors will be returned as a map. Setting this to `true` will pass in an
* array of `ValidationError` to the callback instead.
* @default false
*/
rawErrors?: boolean;
}
/**
* The currently set custom validation error handler, if any.
* To set this, use `.setValidationErrorHandler()`.
*/
export declare let onValidationError: ValidationErrorHandler | undefined;
/**
* Register a callback to run whenever a validation fails.
* @param handler The callback that will receive a map of validation errors.
* @param opts Options
*/
export declare function setValidationErrorHandler(handler: ValidationErrorMapHandler, opts?: ValidationErrorHandlerOptions & {
rawErrors?: false;
}): void;
/**
* Register a callback to run whenever a validation fails.
* @param handler The callback that will receive an array of validation errors.
* @param opts Options
*/
export declare function setValidationErrorHandler(handler: ValidationErrorHandler, opts: ValidationErrorHandlerOptions & {
rawErrors: true;
}): void;
/**
* Unregisters the callback to run when a validation fails, and uses the default behavior.
*/
export declare function clearValidationErrorHandler(): void;