|
9 | 9 | import { AggregationCursor } from './cursor/aggregation_cursor';
|
10 | 10 | import { Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
|
11 | 11 | import { ReadPreference, ReadPreferenceLike } from './read_preference';
|
12 |
| -import { MongoDriverError } from './error'; |
| 12 | +import { MongoDriverError, MongoInvalidArgumentError } from './error'; |
13 | 13 | import { Collection, CollectionOptions } from './collection';
|
14 | 14 | import { ChangeStream, ChangeStreamOptions } from './change_stream';
|
15 | 15 | import * as CONSTANTS from './constants';
|
@@ -287,13 +287,13 @@ export class Db {
|
287 | 287 | */
|
288 | 288 | aggregate(pipeline: Document[] = [], options?: AggregateOptions): AggregationCursor {
|
289 | 289 | if (arguments.length > 2) {
|
290 |
| - throw new MongoDriverError('Third parameter to `db.aggregate()` must be undefined'); |
| 290 | + throw new MongoInvalidArgumentError('Third parameter to `db.aggregate()` must be undefined'); |
291 | 291 | }
|
292 | 292 | if (typeof pipeline === 'function') {
|
293 |
| - throw new MongoDriverError('`pipeline` parameter must not be function'); |
| 293 | + throw new MongoInvalidArgumentError('`pipeline` parameter must not be function'); |
294 | 294 | }
|
295 | 295 | if (typeof options === 'function') {
|
296 |
| - throw new MongoDriverError('`options` parameter must not be function'); |
| 296 | + throw new MongoInvalidArgumentError('`options` parameter must not be function'); |
297 | 297 | }
|
298 | 298 |
|
299 | 299 | return new AggregationCursor(
|
@@ -324,6 +324,7 @@ export class Db {
|
324 | 324 | if (!options) {
|
325 | 325 | options = {};
|
326 | 326 | } else if (typeof options === 'function') {
|
| 327 | + // TODO: Replace this error with a more appropriate error class |
327 | 328 | throw new MongoDriverError('The callback form of this helper has been removed.');
|
328 | 329 | }
|
329 | 330 | const finalOptions = resolveOptions(this, options);
|
@@ -724,15 +725,15 @@ export class Db {
|
724 | 725 | // Validate the database name
|
725 | 726 | function validateDatabaseName(databaseName: string) {
|
726 | 727 | if (typeof databaseName !== 'string')
|
727 |
| - throw new MongoDriverError('database name must be a string'); |
| 728 | + throw new MongoInvalidArgumentError('database name must be a string'); |
728 | 729 | if (databaseName.length === 0)
|
729 |
| - throw new MongoDriverError('database name cannot be the empty string'); |
| 730 | + throw new MongoInvalidArgumentError('database name cannot be the empty string'); |
730 | 731 | if (databaseName === '$external') return;
|
731 | 732 |
|
732 | 733 | const invalidChars = [' ', '.', '$', '/', '\\'];
|
733 | 734 | for (let i = 0; i < invalidChars.length; i++) {
|
734 | 735 | if (databaseName.indexOf(invalidChars[i]) !== -1)
|
735 |
| - throw new MongoDriverError( |
| 736 | + throw new MongoInvalidArgumentError( |
736 | 737 | `database names cannot contain the character '${invalidChars[i]}'`
|
737 | 738 | );
|
738 | 739 | }
|
|
0 commit comments