Skip to content

Commit

Permalink
refactor errors exposure
Browse files Browse the repository at this point in the history
MongooseError base class: mongoose.Error

All MongooseError subclasses: mongoose.Error.xxxx
  • Loading branch information
aheckmann committed Nov 14, 2012
1 parent 9f04f95 commit 1849d74
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 35 deletions.
12 changes: 11 additions & 1 deletion lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 23,14 @@ MongooseError.prototype.__proto__ = Error.prototype;
* Module exports.
*/

module.exports = MongooseError;
module.exports = exports = MongooseError;

/*!
* Expose subclasses
*/

MongooseError.CastError = require('./errors/cast');
MongooseError.DocumentError = require('./errors/document');
MongooseError.ValidationError = require('./errors/validation')
MongooseError.ValidatorError = require('./errors/validator')
MongooseError.VersionError =require('./errors/version')
6 changes: 0 additions & 6 deletions lib/errors/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 475,6 @@ mongoose.Document = Document;

mongoose.Error = require('./error');

/**
* All MongooseErrors
*/

mongoose.Errors = require('./errors')

/**
* The node-mongodb-native driver Mongoose uses.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 3,8 @@
*/

var utils = require('./utils');
var CastError = require('./errors/cast')
var ValidatorError = require('./errors/validator')
var CastError = require('./error').CastError;
var ValidatorError = require('./error').ValidatorError;

/**
* SchemaType constructor
Expand Down
6 changes: 3 additions & 3 deletions test/document.modified.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 10,9 @@ var start = require('./common')
, Query = require('../lib/query')
, Schema = mongoose.Schema
, SchemaType = mongoose.SchemaType
, CastError = mongoose.Errors.CastError
, ValidatorError = mongoose.Errors.ValidatorError
, ValidationError = mongoose.Errors.ValidationError
, CastError = mongoose.Error.CastError
, ValidatorError = mongoose.Error.ValidatorError
, ValidationError = mongoose.Error.ValidationError
, ObjectId = Schema.ObjectId
, DocumentObjectId = mongoose.Types.ObjectId
, DocumentArray = mongoose.Types.DocumentArray
Expand Down
6 changes: 3 additions & 3 deletions test/document.strict.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 10,9 @@ var start = require('./common')
, Query = require('../lib/query')
, Schema = mongoose.Schema
, SchemaType = mongoose.SchemaType
, CastError = mongoose.Errors.CastError
, ValidatorError = mongoose.Errors.ValidatorError
, ValidationError = mongoose.Errors.ValidationError
, CastError = mongoose.Error.CastError
, ValidatorError = mongoose.Error.ValidatorError
, ValidationError = mongoose.Error.ValidationError
, ObjectId = Schema.Types.ObjectId
, DocumentObjectId = mongoose.Types.ObjectId
, DocumentArray = mongoose.Types.DocumentArray
Expand Down
12 changes: 6 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 316,12 @@ describe('mongoose module:', function(){
assert.equal('function', typeof mongoose.Promise);
assert.equal('function', typeof mongoose.Model);
assert.equal('function', typeof mongoose.Document);
assert.equal('Object', mongoose.Errors.constructor.name);
assert.equal('function', typeof mongoose.Errors.CastError);
assert.equal('function', typeof mongoose.Errors.DocumentError);
assert.equal('function', typeof mongoose.Errors.ValidationError);
assert.equal('function', typeof mongoose.Errors.ValidatorError);
assert.equal('function', typeof mongoose.Errors.VersionError);
assert.equal('function', typeof mongoose.Error);
assert.equal('function', typeof mongoose.Error.CastError);
assert.equal('function', typeof mongoose.Error.DocumentError);
assert.equal('function', typeof mongoose.Error.ValidationError);
assert.equal('function', typeof mongoose.Error.ValidatorError);
assert.equal('function', typeof mongoose.Error.VersionError);
done()
})

Expand Down
6 changes: 3 additions & 3 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 10,9 @@ var start = require('./common')
, Query = require('../lib/query')
, Schema = mongoose.Schema
, SchemaType = mongoose.SchemaType
, CastError = mongoose.Errors.CastError
, ValidatorError = mongoose.Errors.ValidatorError
, ValidationError = mongoose.Errors.ValidationError
, CastError = mongoose.Error.CastError
, ValidatorError = mongoose.Error.ValidatorError
, ValidationError = mongoose.Error.ValidationError
, ObjectId = Schema.Types.ObjectId
, DocumentObjectId = mongoose.Types.ObjectId
, DocumentArray = mongoose.Types.DocumentArray
Expand Down
2 changes: 1 addition & 1 deletion test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 10,7 @@ var start = require('./common')
, Document = mongoose.Document
, SchemaType = mongoose.SchemaType
, VirtualType = mongoose.VirtualType
, ValidatorError = mongoose.Errors.ValidatorError
, ValidatorError = mongoose.Error.ValidatorError
, SchemaTypes = Schema.Types
, ObjectId = SchemaTypes.ObjectId
, Mixed = SchemaTypes.Mixed
Expand Down
8 changes: 4 additions & 4 deletions test/versioning.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 16,10 @@ var start = require('./common')
, EmbeddedDocument = mongoose.Types.Embedded
, MongooseArray = mongoose.Types.Array
, MongooseError = mongoose.Error
, CastError = mongoose.Errors.CastError
, ValidatorError = mongoose.Errors.ValidatorError
, ValidationError = mongoose.Errors.ValidationError
, VersionError = mongoose.Errors.VersionError
, CastError = mongoose.Error.CastError
, ValidatorError = mongoose.Error.ValidatorError
, ValidationError = mongoose.Error.ValidationError
, VersionError = mongoose.Error.VersionError
;

/**
Expand Down

0 comments on commit 1849d74

Please sign in to comment.