A specialised Error to indicate a model validation failure.

Hierarchy

  • Error
    • DataModelValidationError

Constructors

Properties

The root validation failure that triggered this error.

Methods

  • Retrieve the root failure that caused this error, or a specific sub-failure via a path.

    Parameters

    • Optional path: string

      The property path to the failure.

    Returns DataModelValidationFailure

    Example: Retrieving a failure.

    const changes = {
    "foo.bar": "validValue",
    "foo.baz": "invalidValue"
    };
    try {
    doc.validate(expandObject(changes));
    } catch ( err ) {
    const failure = err.getFailure("foo.baz");
    console.log(failure.invalidValue); // "invalidValue"
    }
  • Retrieve a flattened object of all the properties that failed validation as part of this error.

    Returns Record<string, DataModelValidationFailure>

    Example: Removing invalid changes from an update delta.

    const changes = {
    "foo.bar": "validValue",
    "foo.baz": "invalidValue"
    };
    try {
    doc.validate(expandObject(changes));
    } catch ( err ) {
    const failures = err.getAllFailures();
    if ( failures ) {
    for ( const prop in failures ) delete changes[prop];
    doc.validate(expandObject(changes));
    }
    }
  • Log the validation error as a table.

    Returns void

  • Generate a nested tree view of the error as an HTML string.

    Returns string