@@ -190,7 +190,7 @@ Model.prototype.db;
190190
191191Model . useConnection = function useConnection ( connection ) {
192192 if ( ! connection ) {
193- throw new Error ( 'Please provide a connection.' ) ;
193+ throw new MongooseError ( 'Please provide a connection.' ) ;
194194 }
195195 if ( this . db ) {
196196 delete this . db . models [ this . modelName ] ;
@@ -825,7 +825,7 @@ Model.prototype.deleteOne = function deleteOne(options) {
825825 // `self` is passed to pre hooks as argument for backwards compatibility, but that
826826 // isn't the actual arguments passed to the wrapped function.
827827 if ( res [ 0 ] !== self || res [ 1 ] !== options ) {
828- throw new Error ( 'Document deleteOne pre hooks cannot overwrite arguments' ) ;
828+ throw new MongooseError ( 'Document deleteOne pre hooks cannot overwrite arguments' ) ;
829829 }
830830 query . deleteOne ( where , options ) ;
831831 // Apply custom where conditions _after_ document deleteOne middleware for
@@ -3610,7 +3610,7 @@ async function buildPreSavePromise(document, options) {
36103610 const preFilter = buildMiddlewareFilter ( options , 'pre' ) ;
36113611 const [ newOptions ] = await document . schema . s . hooks . execPre ( 'save' , document , [ options ] , { filter : preFilter } ) ;
36123612 if ( newOptions !== options ) {
3613- throw new Error ( 'Cannot overwrite options in pre("save") hook on bulkSave()' ) ;
3613+ throw new MongooseError ( 'Cannot overwrite options in pre("save") hook on bulkSave()' ) ;
36143614 }
36153615}
36163616
@@ -3850,15 +3850,15 @@ Model.castObject = function castObject(obj, options) {
38503850
38513851Model . buildBulkWriteOperations = function buildBulkWriteOperations ( documents , options ) {
38523852 if ( ! Array . isArray ( documents ) ) {
3853- throw new Error ( `bulkSave expects an array of documents to be passed, received \`${ documents } \` instead` ) ;
3853+ throw new MongooseError ( `bulkSave expects an array of documents to be passed, received \`${ documents } \` instead` ) ;
38543854 }
38553855
38563856 setDefaultOptions ( ) ;
38573857
38583858 const writeOperations = documents . map ( ( document , i ) => {
38593859 if ( ! options . skipValidation ) {
38603860 if ( ! ( document instanceof Document ) ) {
3861- throw new Error ( `documents.${ i } was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).` ) ;
3861+ throw new MongooseError ( `documents.${ i } was not a mongoose document, documents must be an array of mongoose documents (instanceof mongoose.Document).` ) ;
38623862 }
38633863 if ( options . validateBeforeSave == null || options . validateBeforeSave ) {
38643864 const err = document . validateSync ( ) ;
@@ -4949,7 +4949,7 @@ Model.compile = function compile(name, schema, collectionName, connection, base)
49494949Model . clientEncryption = function clientEncryption ( ) {
49504950 const ClientEncryption = this . base . driver . get ( ) . ClientEncryption ;
49514951 if ( ! ClientEncryption ) {
4952- throw new Error ( 'The mongodb driver must be used to obtain a ClientEncryption object.' ) ;
4952+ throw new MongooseError ( 'The mongodb driver must be used to obtain a ClientEncryption object.' ) ;
49534953 }
49544954
49554955 const client = this . collection ?. conn ?. client ;
0 commit comments