Skip to content

Commit 410f11d

Browse files
committed
chore: Add doc comments to new errors and prevent direct instantiation of MongoAPIError
1 parent 6c4a056 commit 410f11d

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

src/error.ts

+62-11
Original file line numberDiff line numberDiff line change
@@ -245,42 +245,93 @@ export class MongoParseError extends MongoDriverError {
245245
}
246246
}
247247

248+
/**
249+
* An error generated when the user misuses the driver API
250+
*
251+
* @privateRemarks
252+
* Should **never** be directly instantiated
253+
*
254+
* @public
255+
* @category Error
256+
*/
257+
248258
export class MongoAPIError extends MongoDriverError {
249-
constructor(message: string) {
259+
protected constructor(message: string) {
250260
super(message);
251-
this.name = 'MongoAPIError';
261+
}
262+
263+
get name(): string {
264+
return 'MongoAPIError';
252265
}
253266
}
254267

268+
/**
269+
* An error generated when the user supplies malformed or unexpected arguments
270+
* or when a required argument or field is not provided.
271+
*
272+
*
273+
* @public
274+
* @category Error
275+
*/
255276
export class MongoInvalidArgumentError extends MongoAPIError {
256277
constructor(message: string) {
257278
super(message);
258-
this.name = 'MongoInvalidArgumentError';
279+
}
280+
281+
get name(): string {
282+
return 'MongoInvalidArgumentError';
259283
}
260284
}
261285

286+
/**
287+
* An error generated when a feature that is not enabled or allowed for the current server
288+
* configuration is used
289+
*
290+
*
291+
* @public
292+
* @category Error
293+
*/
262294
export class MongoCompatibilityError extends MongoAPIError {
263295
constructor(message: string) {
264296
super(message);
265-
this.name = 'MongoCompatibilityError';
266297
}
267-
}
268-
export class MongoClientInstantiationError extends MongoAPIError {
269-
constructor(message: string) {
270-
super(message);
271-
this.name = 'MongoClientInstantiationError';
298+
299+
get name(): string {
300+
return 'MongoCompatibilityError';
272301
}
273302
}
303+
304+
/**
305+
* An error generated when the user fails to provide authentication credentials before attempting
306+
* to connect to a mongo server instance.
307+
*
308+
*
309+
* @public
310+
* @category Error
311+
*/
274312
export class MongoMissingCredentialsError extends MongoAPIError {
275313
constructor(message: string) {
276314
super(message);
277-
this.name = 'MongoMissingCredentialsError';
315+
}
316+
317+
get name(): string {
318+
return 'MongoMissingCredentialsError';
278319
}
279320
}
321+
322+
/**
323+
* An error generated when a required module or dependency is not present in the local environment
324+
*
325+
* @public
326+
* @category Error
327+
*/
280328
export class MongoMissingDependencyError extends MongoAPIError {
281329
constructor(message: string) {
282330
super(message);
283-
this.name = 'MongoMissingDependencyError';
331+
}
332+
333+
get name(): string {
334+
return 'MongoMissingDependencyError';
284335
}
285336
}
286337
/**

0 commit comments

Comments
 (0)