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.

51 lines
917 B

  1. /*!
  2. * Module dependencies.
  3. */
  4. var MongooseError = require('../error');
  5. /**
  6. * Schema validator error
  7. *
  8. * @param {String} path
  9. * @param {String} msg
  10. * @param {String|Number|any} val
  11. * @inherits MongooseError
  12. * @api private
  13. */
  14. function ValidatorError (path, type, val) {
  15. var msg = type
  16. ? '"' + type + '" '
  17. : '';
  18. var message = 'Validator ' + msg + 'failed for path ' + path
  19. if (2 < arguments.length) message += ' with value `' + String(val) + '`';
  20. MongooseError.call(this, message);
  21. Error.captureStackTrace(this, arguments.callee);
  22. this.name = 'ValidatorError';
  23. this.path = path;
  24. this.type = type;
  25. this.value = val;
  26. };
  27. /*!
  28. * toString helper
  29. */
  30. ValidatorError.prototype.toString = function () {
  31. return this.message;
  32. }
  33. /*!
  34. * Inherits from MongooseError
  35. */
  36. ValidatorError.prototype.__proto__ = MongooseError.prototype;
  37. /*!
  38. * exports
  39. */
  40. module.exports = ValidatorError;