Skip to content

ValidationErrors

ValidationErrors is the collection returned by entities.validate(). Obtain it from validate() or from InstantiationError.errors.

API

SurfaceReturnsBest for
.itemsreadonly ValidationErrorType[]Direct access to raw error objects
.okbooleanQuick valid/invalid check
.lengthnumberError count
[Symbol.iterator]Iterator<ValidationErrorType>for...of iteration
aggregate(){ count, paths, keywords }Structured logs, metric labels
report()ProblemDetailsTypeHTTP 422 response bodies (RFC 7807)

Usage examples

Common projections from errs.items:

ts
// Path-prefixed message strings
errs.items.map(err => `${err.path}: ${err.message}`)

// Group by path
const grouped: Record<string, ValidationErrorType[]> = {};
for (const err of errs) {
  (grouped[err.path || '_root'] ??= []).push(err);
}

// Field vs form errors
const fieldErrors: ValidationErrorType[] = [];
const formErrors: ValidationErrorType[] = [];
for (const err of errs) {
  if (err.path) { fieldErrors.push(err); } else { formErrors.push(err); }
}

All examples use the bookstore domain. See entities.validate() for how to obtain the collection.

See also

Released under the MIT License.