Skip to content

Model Object

errorsOnBase()

errorsOnBase() — returns array

Available in: model Category: Error Functions

Returns an array of all errors associated with the object as a whole (not related to any specific property).

NameTypeRequiredDefaultDescription
namestringno—Specify an error name here to only return errors for that error name.
// 1. Get all general (base) errors for a model object after validation
user = model("User").new(params.user);
user.valid();
errors = user.errorsOnBase();
// errors -> [{property: "", message: "Account has been suspended", name: ""}]

// 2. Filter base errors by a specific error name
user.addErrorToBase(message="Account has been suspended", name="suspended");
user.addErrorToBase(message="Please accept the terms", name="terms");
suspendedErrors = user.errorsOnBase(name="suspended");
// suspendedErrors -> [{property: "", message: "Account has been suspended", name: "suspended"}]

// 3. Check for base errors and display them
errors = user.errorsOnBase();
if (arrayLen(errors)) {
    for (e in errors) {
        writeOutput(e.message);
    }
}