@@ -170,7 +170,7 @@ Aggregate.prototype.append = function() {
170170 : [ ...arguments ] ;
171171
172172 if ( ! args . every ( isOperator ) ) {
173- throw new Error ( 'Arguments must be aggregate pipeline operators' ) ;
173+ throw new MongooseError ( 'Arguments must be aggregate pipeline operators' ) ;
174174 }
175175
176176 this . _pipeline = this . _pipeline . concat ( args ) ;
@@ -203,7 +203,7 @@ Aggregate.prototype.append = function() {
203203 */
204204Aggregate . prototype . addFields = function ( arg ) {
205205 if ( typeof arg !== 'object' || arg === null || Array . isArray ( arg ) ) {
206- throw new Error ( 'Invalid addFields() argument. Must be an object' ) ;
206+ throw new MongooseError ( 'Invalid addFields() argument. Must be an object' ) ;
207207 }
208208 return this . append ( { $addFields : Object . assign ( { } , arg ) } ) ;
209209} ;
@@ -259,7 +259,7 @@ Aggregate.prototype.project = function(arg) {
259259 fields [ field ] = include ;
260260 } ) ;
261261 } else {
262- throw new Error ( 'Invalid project() argument. Must be string or object' ) ;
262+ throw new MongooseError ( 'Invalid project() argument. Must be string or object' ) ;
263263 }
264264
265265 return this . append ( { $project : fields } ) ;
@@ -462,7 +462,7 @@ Aggregate.prototype.unwind = function() {
462462 $unwind : ( arg [ 0 ] === '$' ) ? arg : '$' + arg
463463 } ) ;
464464 } else {
465- throw new Error ( 'Invalid arg "' + arg + '" to unwind(), ' +
465+ throw new MongooseError ( 'Invalid arg "' + arg + '" to unwind(), ' +
466466 'must be string or object' ) ;
467467 }
468468 }
@@ -761,7 +761,7 @@ Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
761761 if ( arguments . length === 3 ) {
762762 if ( ( typeof thenExpr === 'string' && ! validRedactStringValues . has ( thenExpr ) ) ||
763763 ( typeof elseExpr === 'string' && ! validRedactStringValues . has ( elseExpr ) ) ) {
764- throw new Error ( 'If thenExpr or elseExpr is string, it must be either $$DESCEND, $$PRUNE or $$KEEP' ) ;
764+ throw new MongooseError ( 'If thenExpr or elseExpr is string, it must be either $$DESCEND, $$PRUNE or $$KEEP' ) ;
765765 }
766766
767767 expression = {
@@ -796,7 +796,7 @@ Aggregate.prototype.explain = async function explain(verbosity) {
796796 const model = this . _model ;
797797
798798 if ( ! this . _pipeline . length ) {
799- throw new Error ( 'Aggregate has empty pipeline' ) ;
799+ throw new MongooseError ( 'Aggregate has empty pipeline' ) ;
800800 }
801801
802802 prepareDiscriminatorPipeline ( this . _pipeline , this . _model . schema ) ;
@@ -1058,7 +1058,7 @@ Aggregate.prototype.pipelineForUnionWith = function pipelineForUnionWith() {
10581058
10591059Aggregate . prototype . exec = async function exec ( ) {
10601060 if ( ! this . _model && ! this . _connection ) {
1061- throw new Error ( 'Aggregate not bound to any Model' ) ;
1061+ throw new MongooseError ( 'Aggregate not bound to any Model' ) ;
10621062 }
10631063 if ( typeof arguments [ 0 ] === 'function' ) {
10641064 throw new MongooseError ( 'Aggregate.prototype.exec() no longer accepts a callback' ) ;
0 commit comments