Skip to content

Commit a4bba28

Browse files
committed
feat(NODE-3419): defined MongoRuntimeError children
1 parent cb0db49 commit a4bba28

File tree

1 file changed

+232
-6
lines changed

1 file changed

+232
-6
lines changed

src/error.ts

Lines changed: 232 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export class MongoRuntimeError extends MongoDriverError {
202202
* An error generated when a batch command is reexecuted after one of the commands in the batch
203203
* has failed
204204
*
205-
*
206205
* @public
207206
* @category Error
208207
*/
@@ -216,11 +215,60 @@ export class MongoBatchReExecutionError extends MongoRuntimeError {
216215
}
217216
}
218217

218+
/**
219+
* An error generated when the user supplies an incorrect URI to the driver.
220+
*
221+
* @public
222+
* @category Error
223+
*/
224+
export class MongoURIError extends MongoRuntimeError {
225+
constructor(message: string) {
226+
super(message);
227+
}
228+
229+
get name(): string {
230+
return 'MongoURIError';
231+
}
232+
}
233+
234+
/**
235+
* An error generated when the driver fails to compress data
236+
* before sending it to the server.
237+
*
238+
* @public
239+
* @category Error
240+
*/
241+
export class MongoCompressionError extends MongoRuntimeError {
242+
constructor(message: string) {
243+
super(message);
244+
}
245+
246+
get name(): string {
247+
return 'MongoCompressionError';
248+
}
249+
}
250+
251+
/**
252+
* An error generated when the driver fails to decompress
253+
* data received from the server.
254+
*
255+
* @public
256+
* @category Error
257+
*/
258+
export class MongoDecompressionError extends MongoRuntimeError {
259+
constructor(message: string) {
260+
super(message);
261+
}
262+
263+
get name(): string {
264+
return 'MongoDecompressionError';
265+
}
266+
}
267+
219268
/**
220269
* An error thrown when the user attempts to operate on a database or collection through a MongoClient
221270
* that has not yet successfully called the "connect" method
222271
*
223-
*
224272
* @public
225273
* @category Error
226274
*/
@@ -234,11 +282,61 @@ export class MongoNotConnectedError extends MongoRuntimeError {
234282
}
235283
}
236284

285+
/**
286+
* An error generated when the user makes a mistake in the usage of transactions.
287+
* (e.g. attempting to commit a transaction with a readPreference other than primary)
288+
*
289+
* @public
290+
* @category Error
291+
*/
292+
export class MongoTransactionError extends MongoRuntimeError {
293+
constructor(message: string) {
294+
super(message);
295+
}
296+
297+
get name(): string {
298+
return 'MongoTransactionError';
299+
}
300+
}
301+
302+
/**
303+
* An error generated when the user attempts to operate
304+
* on a session that has expired or has been closed.
305+
*
306+
* @public
307+
* @category Error
308+
*/
309+
export class MongoExpiredSessionError extends MongoRuntimeError {
310+
constructor(message: string) {
311+
super(message);
312+
}
313+
314+
get name(): string {
315+
return 'MongoExpiredSessionError';
316+
}
317+
}
318+
319+
/**
320+
* A error generated when the user attempts to authenticate
321+
* via Kerberos, but fails to connect to the Kerberos client.
322+
*
323+
* @public
324+
* @category Error
325+
*/
326+
export class MongoKerberosError extends MongoRuntimeError {
327+
constructor(message: string) {
328+
super(message);
329+
}
330+
331+
get name(): string {
332+
return 'MongoKerberosError';
333+
}
334+
}
335+
237336
/**
238337
* An error thrown when the user attempts to operate on a cursor that is in a state which does not
239338
* support the attempted operation.
240339
*
241-
*
242340
* @public
243341
* @category Error
244342
*/
@@ -253,8 +351,39 @@ export class MongoCursorError extends MongoRuntimeError {
253351
}
254352

255353
/**
256-
* An error thrown when the user calls a function or method not supported on a tailable cursor
354+
* An error generated when a stream operation fails to execute.
355+
*
356+
* @public
357+
* @category Error
358+
*/
359+
export class MongoStreamError extends MongoRuntimeError {
360+
constructor(message: string) {
361+
super(message);
362+
}
363+
364+
get name(): string {
365+
return 'MongoStreamError';
366+
}
367+
}
368+
369+
/**
370+
* An error generated when a ChangeStream operation fails to execute.
257371
*
372+
* @public
373+
* @category Error
374+
*/
375+
export class MongoChangeStreamError extends MongoStreamError {
376+
constructor(message: string) {
377+
super(message);
378+
}
379+
380+
get name(): string {
381+
return 'MongoChangeStreamError';
382+
}
383+
}
384+
385+
/**
386+
* An error thrown when the user calls a function or method not supported on a tailable cursor
258387
*
259388
* @public
260389
* @category Error
@@ -269,11 +398,42 @@ export class MongoTailableCursorError extends MongoCursorError {
269398
}
270399
}
271400

401+
/** An error generated when a GridFSStream operation fails to execute.
402+
*
403+
* @public
404+
* @category Error
405+
*/
406+
export class MongoGridFSStreamError extends MongoStreamError {
407+
constructor(message: string) {
408+
super(message);
409+
}
410+
411+
get name(): string {
412+
return 'MongoGridFSStreamError';
413+
}
414+
}
415+
416+
/**
417+
* An error generated when a malformed or invalid chunk is
418+
* encountered when reading from a GridFSStream.
419+
*
420+
* @public
421+
* @category Error
422+
*/
423+
export class MongoGridFSChunkError extends MongoStreamError {
424+
constructor(message: string) {
425+
super(message);
426+
}
427+
428+
get name(): string {
429+
return 'MongoGridFSChunkError';
430+
}
431+
}
432+
272433
/**
273434
* An error thrown when the user attempts to add options to a cursor that has already been
274435
* initialized
275436
*
276-
*
277437
* @public
278438
* @category Error
279439
*/
@@ -287,9 +447,41 @@ export class MongoCursorInUseError extends MongoCursorError {
287447
}
288448
}
289449

450+
/** An error generated when an attempt to access a resource
451+
* which has already been or will be closed/destroyed.
452+
*
453+
* @public
454+
* @category Error
455+
*/
456+
export class MongoResourceClosedError extends MongoRuntimeError {
457+
constructor(message: string) {
458+
super(message);
459+
}
460+
461+
get name(): string {
462+
return 'MongoResourceClosedError';
463+
}
464+
}
465+
290466
/**
291-
* An error thrown when an attempt is made to read from a cursor that has been exhausted
467+
* An error generated when an attempt is made to operate
468+
* on a closed/closing server.
292469
*
470+
* @public
471+
* @category Error
472+
*/
473+
export class MongoServerClosedError extends MongoResourceClosedError {
474+
constructor(message: string) {
475+
super(message);
476+
}
477+
478+
get name(): string {
479+
return 'MongoServerClosedError';
480+
}
481+
}
482+
483+
/**
484+
* An error thrown when an attempt is made to read from a cursor that has been exhausted
293485
*
294486
* @public
295487
* @category Error
@@ -304,6 +496,40 @@ export class MongoCursorExhaustedError extends MongoCursorError {
304496
}
305497
}
306498

499+
/**
500+
* An error generated when an attempt is made to operate
501+
* on a closed/closing stream.
502+
*
503+
* @public
504+
* @category Error
505+
*/
506+
export class MongoStreamClosedError extends MongoResourceClosedError {
507+
constructor(message: string) {
508+
super(message);
509+
}
510+
511+
get name(): string {
512+
return 'MongoStreamClosedError';
513+
}
514+
}
515+
516+
/**
517+
* An error generated when an attempt is made to operate on a
518+
* dropped, or otherwise unavailable, database.
519+
*
520+
* @public
521+
* @category Error
522+
*/
523+
export class MongoTopologyClosedError extends MongoResourceClosedError {
524+
constructor(message: string) {
525+
super(message);
526+
}
527+
528+
get name(): string {
529+
return 'MongoTopologyClosedError';
530+
}
531+
}
532+
307533
/** @internal */
308534
const kBeforeHandshake = Symbol('beforeHandshake');
309535
export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean {

0 commit comments

Comments
 (0)