Documentation

ManagedRecordValidationError

interface ManagedRecordValidationError

extends Error

Constructor for ManagedRecordValidationError errors, may be used by the ManagedRecord.validate method to encapsulate multiple errors.

If the arguments list includes another validation error, its encapsulated errors are added to the list instead of the ManagedRecordValidationError object itself.

See Also

ManagedRecord.validate(), ManagedRecord.isValidationError()

Example

// class that extends some other class defined elsewhere
class MyRecord extends SomeOtherRecord {
  // this property is validated below:
  name?: string;

  validate() {
    // validate other fields first
    let errors: any[] = [];
    try { super.validate() }
    catch (err) { errors.push(err) }

    // validate own property:
    if (!this.name) {
      errors.push("Name cannot be left blank");
    }
    if (errors.length) {
      throw new ManagedRecordValidationError(...errors);
    }
  }
}

.isValidationError

true

Validation error flag, always set to true.

.errors

({} | Error)[]

List of encapsulated errors.