ValidationException
ValidationException is thrown by validator.validate() when validation fails.
Import
ts
import { ValidationException } from 'kanun';Typical Usage
ts
try {
await validator.validate();
} catch (error) {
if (error instanceof ValidationException) {
console.log(error.message);
console.log(error.errors());
}
}Properties
validator: the validator instancestatus: HTTP-style status code (default422)errorBag: named bag (defaultdefault)redirectTo: optional redirect targetmessage: summarized first validation error
Methods
errors(): Record<string, string[]>
Returns structured errors by field.
toResponse()
Returns a response-friendly payload with message and errors.
setStatus(status)
Sets response status and returns the same exception.
setErrorBag(name)
Sets the error bag name.
setRedirectTo(url)
Sets redirect URL metadata.
withMessages(messages) (static)
Builds an exception from plain messages.