-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0_baseClass.js
More file actions
executable file
·38 lines (30 loc) · 974 Bytes
/
0_baseClass.js
File metadata and controls
executable file
·38 lines (30 loc) · 974 Bytes
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
'use strict';
// Base error classes to extend from.
// Use assertions to catch programming errors.
// https://en.wikipedia.org/wiki/Assertion_%28software_development%29#Comparison_with_error_handling
class ApplicationError extends Error {
constructor(message, options = {}) {
assert(typeof message === 'string');
assert(typeof options === 'object');
assert(options !== null);
assert(!Object.prototype.hasOwnProperty.call(options, 'stack'))
super(message);
// Attach relevant information to the error instance
// (e.g., the username).
for (const [key, value] of Object.entries(options)) {
this[key] = value;
}
}
get name() {
return this.constructor.name;
}
}
class OutgoingRequestError extends ApplicationError {}
class DatabaseError extends ApplicationError {}
class UserFacingError extends ApplicationError {}
module.exports = {
ApplicationError,
DatabaseError,
OutgoingRequestError,
UserFacingError
};