You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
890 B

  1. /*!
  2. * Module requirements
  3. */
  4. var MongooseError = require('../error')
  5. /**
  6. * Document Validation Error
  7. *
  8. * @api private
  9. * @param {Document} instance
  10. * @inherits MongooseError
  11. */
  12. function ValidationError (instance) {
  13. MongooseError.call(this, "Validation failed");
  14. Error.captureStackTrace(this, arguments.callee);
  15. this.name = 'ValidationError';
  16. this.errors = instance.errors = {};
  17. };
  18. /**
  19. * Console.log helper
  20. */
  21. ValidationError.prototype.toString = function () {
  22. var ret = this.name + ': ';
  23. var msgs = [];
  24. Object.keys(this.errors).forEach(function (key) {
  25. if (this == this.errors[key]) return;
  26. msgs.push(String(this.errors[key]));
  27. }, this)
  28. return ret + msgs.join(', ');
  29. };
  30. /*!
  31. * Inherits from MongooseError.
  32. */
  33. ValidationError.prototype.__proto__ = MongooseError.prototype;
  34. /*!
  35. * Module exports
  36. */
  37. module.exports = exports = ValidationError;