objectExpected.js 637 B

123456789101112131415161718192021222324252627282930
  1. /*!
  2. * Module dependencies.
  3. */
  4. 'use strict';
  5. const MongooseError = require('./');
  6. class ObjectExpectedError extends MongooseError {
  7. /**
  8. * Strict mode error constructor
  9. *
  10. * @param {string} type
  11. * @param {string} value
  12. * @api private
  13. */
  14. constructor(path, val) {
  15. const typeDescription = Array.isArray(val) ? 'array' : 'primitive value';
  16. super('Tried to set nested object field `' + path +
  17. `\` to ${typeDescription} \`` + val + '`');
  18. this.path = path;
  19. }
  20. }
  21. Object.defineProperty(ObjectExpectedError.prototype, 'name', {
  22. value: 'ObjectExpectedError'
  23. });
  24. module.exports = ObjectExpectedError;