forked from denodrivers/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.ts
69 lines (63 loc) · 1.39 KB
/
error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Representation of a MongoDB server error response.
* @public
*/
export interface MongoErrorInfo {
ok: 0;
errmsg: string;
code: number;
codeName: string;
}
/**
* A base class from which Mongo errors are derived.
* @public
*/
export abstract class MongoError extends Error {
constructor(info: MongoErrorInfo | string) {
super(`MongoError: ${JSON.stringify(info)}`);
}
}
/**
* A class representation of an error ocurring during the driver's execution.
* @public
*/
export class MongoDriverError extends MongoError {
/**
* @param info A string containing the error's message.
*/
constructor(info: string) {
super(info);
}
}
/**
* A class representation of an error returned by MongoDB server.
* @public
*/
export class MongoServerError extends MongoError implements MongoErrorInfo {
ok: 0;
errmsg: string;
code: number;
codeName: string;
/**
* @param info An object representing the server's error response.
*/
constructor(info: MongoErrorInfo) {
super(info);
this.ok = info.ok;
this.errmsg = info.errmsg;
this.code = info.code;
this.codeName = info.codeName;
}
}
/**
* A class representation of a command with invalid arguments
* @public
*/
export class MongoInvalidArgumentError extends MongoError {
/**
* @param info A string containing the error's message.
*/
constructor(info: string) {
super(info);
}
}