-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomError.js
More file actions
32 lines (29 loc) · 821 Bytes
/
CustomError.js
File metadata and controls
32 lines (29 loc) · 821 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
class CustomError extends Error {
static get NAME_AUTHENTICATION_ERROR() {
return 'AuthenticationError';
}
static get NAME_AUTHORIZATION_ERROR() {
return 'AuthorizationError';
}
static get NAME_VALUE_ERROR() {
return 'ValueError';
}
constructor(message, statusCode) {
super(message);
this.name = this.constructor.name;
this.statusCode = statusCode;
if (this.statusCode === 401) {
this.name = this.constructor.NAME_AUTHENTICATION_ERROR;
}
if (this.statusCode === 403) {
this.name = this.constructor.NAME_AUTHORIZATION_ERROR;
}
if (this.statusCode === 400) {
this.name = this.constructor.NAME_VALUE_ERROR;
}
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
}
module.exports = CustomError;