objectExpected.js 885 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. * Module dependencies.
  3. */
  4. 'use strict';
  5. const MongooseError = require('./');
  6. /**
  7. * Strict mode error constructor
  8. *
  9. * @param {String} type
  10. * @param {String} value
  11. * @inherits MongooseError
  12. * @api private
  13. */
  14. function ObjectExpectedError(path, val) {
  15. const typeDescription = Array.isArray(val) ? 'array' : 'primitive value';
  16. MongooseError.call(this, 'Tried to set nested object field `' + path +
  17. `\` to ${typeDescription} \`` + val + '` and strict mode is set to throw.');
  18. this.name = 'ObjectExpectedError';
  19. if (Error.captureStackTrace) {
  20. Error.captureStackTrace(this);
  21. } else {
  22. this.stack = new Error().stack;
  23. }
  24. this.path = path;
  25. }
  26. /*!
  27. * Inherits from MongooseError.
  28. */
  29. ObjectExpectedError.prototype = Object.create(MongooseError.prototype);
  30. ObjectExpectedError.prototype.constructor = MongooseError;
  31. module.exports = ObjectExpectedError;