Skip to content

Commit

Permalink
docs: add MongooseError to API docs and add list of error names
Browse files Browse the repository at this point in the history
Fix #7509
  • Loading branch information
vkarpov15 committed Feb 17, 2019
1 parent b5f1723 commit aa43200
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/source/api.js
Expand Up @@ -16,6 +16,7 @@ const files = [
'lib/schema.js',
'lib/connection.js',
'lib/document.js',
'lib/error/mongooseError.js',
'lib/model.js',
'lib/query.js',
'lib/cursor/QueryCursor.js',
Expand Down Expand Up @@ -54,7 +55,7 @@ function parse() {
const lastSlash = name.lastIndexOf('/');
name = name.substr(lastSlash === -1 ? 0 : lastSlash + 1);
const data = {
name: name.charAt(0).toUpperCase() === name.charAt(0) ? name : _.capitalize(name),
name: name.charAt(0).toUpperCase() === name.charAt(0) ? name : name.charAt(0).toUpperCase() + name.substr(1),
props: []
};

Expand Down Expand Up @@ -130,6 +131,7 @@ function parse() {
}
}

console.log(ctx);
// Backwards compat
if (typeof ctx.constructor === 'string') {
ctx.anchorId = `${ctx.constructor.toLowerCase()}_${ctx.constructor}-${ctx.name}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Expand Up @@ -405,7 +405,7 @@ Connection.prototype.onOpen = function() {
* @param {Object} [options] Passed on to http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html#connect
* @param {Function} [callback]
* @returns {Connection} this
* @api private
* @api public
*/

Connection.prototype.openUri = function(uri, options, callback) {
Expand Down
3 changes: 2 additions & 1 deletion lib/error/disconnected.js
Expand Up @@ -7,7 +7,8 @@
const MongooseError = require('./');

/**
* Casting Error constructor.
* The connection failed to reconnect and will never successfully reconnect to
* MongoDB without manual intervention.
*
* @param {String} type
* @param {String} value
Expand Down
33 changes: 30 additions & 3 deletions lib/error/mongooseError.js
@@ -1,12 +1,13 @@
'use strict';

/**
* MongooseError constructor
* MongooseError constructor. MongooseError is the base class for all
* Mongoose-specific errors.
*
* @param {String} msg Error message
* @inherits Error https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
*/

'use strict';

function MongooseError(msg) {
Error.call(this);
if (Error.captureStackTrace) {
Expand All @@ -25,4 +26,30 @@ function MongooseError(msg) {
MongooseError.prototype = Object.create(Error.prototype);
MongooseError.prototype.constructor = Error;

/**
* The name of the error. The name uniquely identifies this Mongoose error. The
* possible values are:
*
* - `MongooseError`: general Mongoose error
* - `CastError`: Mongoose could not convert a value to the type defined in the schema path. May be in a `ValidationError` class' `errors` property.
* - `DisconnectedError`: This [connection](connections.html) timed out in trying to reconnect to MongoDB and will not successfully reconnect to MongoDB unless you explicitly reconnect.
* - `DivergentArrayError`: You attempted to `save()` an array that was modified after you loaded it with a `$elemMatch` or similar projection
* - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](api.html#mongoose_Mongoose-model) that was not defined
* - `DocumentNotFoundError`: The document you tried to [`save()`](api.html#document_Document-save) was not found
* - `ValidatorError`: error from an individual schema path's validator
* - `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.
* - `MissingSchemaError`: You called `mongoose.Document()` without a schema
* - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](guide.html#strict).
* - `ObjectParameterError`: Thrown when you pass a non-object value to a function which expects an object as a paramter
* - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](api.html#mongoose_Mongoose-model) to re-define a model that was already defined.
* - `ParallelSaveError`: Thrown when you call [`save()`](api.html#model_Model-save) on a document when the same document instance is already saving.
* - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](guide.html#strict) is set to `throw`.
* - `VersionError`: Thrown when the [document is out of sync](guide.html#versionKey)
*
* @api public
* @property name
* @memberOf MongooseError
* @instance
*/

module.exports = MongooseError;

0 comments on commit aa43200

Please sign in to comment.