From a1181a6f15b845952d54bcae25f4fd73d9d465b1 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 8 Jul 2021 12:47:50 -0400 Subject: [PATCH 1/2] feat: Add new Error classess Add: - MongoBatchReExecutionError - MongoNotConnectedError - MongoCursorError - MongoCursorExhaustedError - MongoTailableCursorError - MongoCursorInUseError --- src/error.ts | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/error.ts b/src/error.ts index 6e721b39f0..4294e2c9e3 100644 --- a/src/error.ts +++ b/src/error.ts @@ -198,6 +198,112 @@ export class MongoRuntimeError extends MongoDriverError { } } +/** + * An error generated when a batch command is reexecuted after one of the commands in the batch + * has failed + * + * + * @public + * @category Error + */ +export class MongoBatchReExecutionError extends MongoRuntimeError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoBatchReExecutionError'; + } +} + +/** + * An Error thrown when the user attempts to operate on a database or collection through a MongoClient + * that has not yet successfully called the "connect" method + * + * + * @public + * @category Error + */ +export class MongoNotConnectedError extends MongoRuntimeError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoNotConnectedError'; + } +} + +/** + * An error thrown when the user attempts to operate on a cursor that is in a state which does not + * support the attempted operation. + * + * + * @public + * @category Error + */ +export class MongoCursorError extends MongoRuntimeError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoCursorError'; + } +} + +/** + * An error thrown when the user calls a function or method not supported on a tailable cursor + * + * + * @public + * @category Error + */ +export class MongoTailableCursorError extends MongoCursorError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoTailableCursorError'; + } +} + +/** + * An error thrown when the user attempts to add options to a cursor that has already been + * initialized + * + * + * @public + * @category Error + */ +export class MongoCursorInUseError extends MongoCursorError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoCursorInUseError'; + } +} + +/** + * An error thrown when an attempt is made to read from a cursor that has been exhausted + * + * + * @public + * @category Error + */ +export class MongoCursorExhaustedError extends MongoCursorError { + constructor(message: string) { + super(message); + } + + get name(): string { + return 'MongoCursorExhaustedError'; + } +} + /** @internal */ const kBeforeHandshake = Symbol('beforeHandshake'); export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean { From 98e00051566a59b645540ec12279d33a2eea7211 Mon Sep 17 00:00:00 2001 From: Andy Mina Date: Fri, 9 Jul 2021 14:00:18 -0400 Subject: [PATCH 2/2] docs(NODE-3403): fixes typo in MongoNotConnectedError Co-authored-by: Eric Adum --- src/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.ts b/src/error.ts index 4294e2c9e3..7d96dc49ac 100644 --- a/src/error.ts +++ b/src/error.ts @@ -217,7 +217,7 @@ export class MongoBatchReExecutionError extends MongoRuntimeError { } /** - * An Error thrown when the user attempts to operate on a database or collection through a MongoClient + * An error thrown when the user attempts to operate on a database or collection through a MongoClient * that has not yet successfully called the "connect" method * *