Skip to content

Commit cb0db49

Browse files
authored
feat(NODE-3403): define MongoRuntimeError children (#2894)
- MongoBatchReExecutionError - MongoNotConnectedError - MongoCursorError - MongoCursorExhaustedError - MongoTailableCursorError - MongoCursorInUseError
1 parent c12979a commit cb0db49

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

src/error.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,112 @@ export class MongoRuntimeError extends MongoDriverError {
198198
}
199199
}
200200

201+
/**
202+
* An error generated when a batch command is reexecuted after one of the commands in the batch
203+
* has failed
204+
*
205+
*
206+
* @public
207+
* @category Error
208+
*/
209+
export class MongoBatchReExecutionError extends MongoRuntimeError {
210+
constructor(message: string) {
211+
super(message);
212+
}
213+
214+
get name(): string {
215+
return 'MongoBatchReExecutionError';
216+
}
217+
}
218+
219+
/**
220+
* An error thrown when the user attempts to operate on a database or collection through a MongoClient
221+
* that has not yet successfully called the "connect" method
222+
*
223+
*
224+
* @public
225+
* @category Error
226+
*/
227+
export class MongoNotConnectedError extends MongoRuntimeError {
228+
constructor(message: string) {
229+
super(message);
230+
}
231+
232+
get name(): string {
233+
return 'MongoNotConnectedError';
234+
}
235+
}
236+
237+
/**
238+
* An error thrown when the user attempts to operate on a cursor that is in a state which does not
239+
* support the attempted operation.
240+
*
241+
*
242+
* @public
243+
* @category Error
244+
*/
245+
export class MongoCursorError extends MongoRuntimeError {
246+
constructor(message: string) {
247+
super(message);
248+
}
249+
250+
get name(): string {
251+
return 'MongoCursorError';
252+
}
253+
}
254+
255+
/**
256+
* An error thrown when the user calls a function or method not supported on a tailable cursor
257+
*
258+
*
259+
* @public
260+
* @category Error
261+
*/
262+
export class MongoTailableCursorError extends MongoCursorError {
263+
constructor(message: string) {
264+
super(message);
265+
}
266+
267+
get name(): string {
268+
return 'MongoTailableCursorError';
269+
}
270+
}
271+
272+
/**
273+
* An error thrown when the user attempts to add options to a cursor that has already been
274+
* initialized
275+
*
276+
*
277+
* @public
278+
* @category Error
279+
*/
280+
export class MongoCursorInUseError extends MongoCursorError {
281+
constructor(message: string) {
282+
super(message);
283+
}
284+
285+
get name(): string {
286+
return 'MongoCursorInUseError';
287+
}
288+
}
289+
290+
/**
291+
* An error thrown when an attempt is made to read from a cursor that has been exhausted
292+
*
293+
*
294+
* @public
295+
* @category Error
296+
*/
297+
export class MongoCursorExhaustedError extends MongoCursorError {
298+
constructor(message: string) {
299+
super(message);
300+
}
301+
302+
get name(): string {
303+
return 'MongoCursorExhaustedError';
304+
}
305+
}
306+
201307
/** @internal */
202308
const kBeforeHandshake = Symbol('beforeHandshake');
203309
export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean {

0 commit comments

Comments
 (0)