error.js
2.2 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
var util = require('util');
/**
* Creates a new MongoError
* @class
* @augments Error
* @param {Error|string|object} message The error message
* @property {string} message The error message
* @property {string} stack The error call stack
* @return {MongoError} A MongoError instance
*/
function MongoError(message) {
var tmp = Error.apply(this, arguments);
tmp.name = this.name = 'MongoError';
if (message instanceof Error) {
this.message = message.message;
this.stack = message.stack;
} else {
if (typeof message === 'string') {
this.message = message;
} else {
this.message = message.message || message.errmsg || message.$err || 'n/a';
for (var name in message) {
this[name] = message[name];
}
}
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
util.inherits(MongoError, Error);
/**
* Creates a new MongoError object
* @method
* @param {Error|string|object} options The options used to create the error.
* @return {MongoError} A MongoError instance
* @deprecated Use `new MongoError()` instead.
*/
MongoError.create = function(options) {
return new MongoError(options);
};
/**
* Creates a new MongoNetworkError
* @class
* @param {Error|string|object} message The error message
* @property {string} message The error message
* @property {string} stack The error call stack
* @return {MongoNetworkError} A MongoNetworkError instance
* @extends {MongoError}
*/
var MongoNetworkError = function(message) {
MongoError.call(this, message);
this.name = 'MongoNetworkError';
};
util.inherits(MongoNetworkError, MongoError);
/**
* An error used when attempting to parse a value (like a connection string)
*
* @class
* @param {Error|string|object} message The error message
* @property {string} message The error message
* @return {MongoParseError} A MongoNetworkError instance
* @extends {MongoError}
*/
const MongoParseError = function(message) {
MongoError.call(this, message);
this.name = 'MongoParseError';
};
util.inherits(MongoParseError, MongoError);
module.exports = {
MongoError: MongoError,
MongoNetworkError: MongoNetworkError,
MongoParseError: MongoParseError
};