Browse files

refactor errors exposure

MongooseError base class: mongoose.Error

All MongooseError subclasses: mongoose.Error.xxxx
  • Loading branch information...
1 parent 9f04f95 commit 1849d746c94fbf8e05092730637dc64130b5f6c0 @aheckmann aheckmann committed Nov 14, 2012
View
12 lib/error.js
@@ -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')
View
6 lib/errors/index.js
@@ -1,6 +0,0 @@
-
-exports.CastError = require('./cast');
-exports.DocumentError = require('./document');
-exports.ValidationError = require('./validation')
-exports.ValidatorError = require('./validator')
-exports.VersionError =require('./version')
View
6 lib/index.js
@@ -476,12 +476,6 @@ mongoose.Document = Document;
mongoose.Error = require('./error');
/**
- * All MongooseErrors
- */
-
-mongoose.Errors = require('./errors')
-
-/**
* The node-mongodb-native driver Mongoose uses.
*
* @api public
View
4 lib/schematype.js
@@ -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
View
6 test/document.modified.test.js
@@ -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
View
6 test/document.strict.test.js
@@ -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
View
12 test/index.test.js
@@ -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()
})
View
6 test/model.test.js
@@ -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
View
2 test/schema.test.js
@@ -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
View
8 test/versioning.test.js
@@ -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
;
/**

0 comments on commit 1849d74

Please sign in to comment.