mongooseError.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. * MongooseError constructor. MongooseError is the base class for all
  4. * Mongoose-specific errors.
  5. *
  6. * @param {String} msg Error message
  7. * @inherits Error https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
  8. */
  9. function MongooseError(msg) {
  10. Error.call(this);
  11. if (Error.captureStackTrace) {
  12. Error.captureStackTrace(this);
  13. } else {
  14. this.stack = new Error().stack;
  15. }
  16. this.message = msg;
  17. this.name = 'MongooseError';
  18. }
  19. /*!
  20. * Inherits from Error.
  21. */
  22. MongooseError.prototype = Object.create(Error.prototype);
  23. MongooseError.prototype.constructor = Error;
  24. /**
  25. * The name of the error. The name uniquely identifies this Mongoose error. The
  26. * possible values are:
  27. *
  28. * - `MongooseError`: general Mongoose error
  29. * - `CastError`: Mongoose could not convert a value to the type defined in the schema path. May be in a `ValidationError` class' `errors` property.
  30. * - `DisconnectedError`: This [connection](connections.html) timed out in trying to reconnect to MongoDB and will not successfully reconnect to MongoDB unless you explicitly reconnect.
  31. * - `DivergentArrayError`: You attempted to `save()` an array that was modified after you loaded it with a `$elemMatch` or similar projection
  32. * - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](api.html#mongoose_Mongoose-model) that was not defined
  33. * - `DocumentNotFoundError`: The document you tried to [`save()`](api.html#document_Document-save) was not found
  34. * - `ValidatorError`: error from an individual schema path's validator
  35. * - `ValidationError`: error returned from [`validate()`](api.html#document_Document-validate) or [`validateSync()`](api.html#document_Document-validateSync). Contains zero or more `ValidatorError` instances in `.errors` property.
  36. * - `MissingSchemaError`: You called `mongoose.Document()` without a schema
  37. * - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](guide.html#strict).
  38. * - `ObjectParameterError`: Thrown when you pass a non-object value to a function which expects an object as a paramter
  39. * - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](api.html#mongoose_Mongoose-model) to re-define a model that was already defined.
  40. * - `ParallelSaveError`: Thrown when you call [`save()`](api.html#model_Model-save) on a document when the same document instance is already saving.
  41. * - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](guide.html#strict) is set to `throw`.
  42. * - `VersionError`: Thrown when the [document is out of sync](guide.html#versionKey)
  43. *
  44. * @api public
  45. * @property name
  46. * @memberOf MongooseError
  47. * @instance
  48. */
  49. module.exports = MongooseError;