next A function to invoke in case the error is not needed to be catched and instead is needed to be passed further.
Return value
The Validation object.
Exceptions
If anything other than a function is passed in the corresponding error will be thrown.
Description
Adds error state callbacks to the Validation object. Once the Validation is in the error state, the callbacks will be invoked one by one in the order they were added. The main purpose of error state callbacks is to perform side effects related to the error state.
When validating groupingValidation objects, unlike other state callbacks, error state callbacks of their grouped validations will not be triggered.
This method catches errors that occur in predicate functions and in their associated state callbacks and other state callbacks of the Validation (and its grouped validations) when the Validation.validate() method gets invoked (or the Validation object is used as an event handler or middleware).
If you want to just perform side effects and not to catch the error on this level, it is possible to forward the error further to return a rejected Promise from the Validation().validate() method or from the middleware by calling the function passed into a callback as the parameter next. This may be used to trigger the Express error handling middleware. If you add several error state callbacks in a row, calling the function next in only one of them is enough.