node-persist icon indicating copy to clipboard operation
node-persist copied to clipboard

Enhanced validation function

Open alejom99 opened this issue 11 years ago • 1 comments

Would it be possible to enhance the validate call from Connection to also accept a list of errors? Also, create a new error object named ValidationError to replace the Error object.

...
  return obj.validate(function(success, message, errors) {
    if (success) {
      return doModelValidation();
    }
    return callback(new ValidationError("Validation failed: " + message, errors));
  });
...

The ValidationError object would be something like:

  function ValidationError(message, errors){
    this.message = message;
    this.errors = errors;
  }
  ValidationError.prototype = new Error();

The proposal above would make it easier to get all validation errors from the Model instead of just getting one error message. I could fork the repository, make the changes and send a pull request if you think is worth it.

Thanks

alejom99 avatar Sep 06 '13 13:09 alejom99

+1

peruzzo avatar Sep 09 '13 19:09 peruzzo