-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
56 lines (47 loc) · 1.63 KB
/
client.js
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
'use strict';
const DEFAULT_MESSAGES = require('./constants/defaultMessages');
const HTTP_STATUS_CODES = require('./constants/httpStatusCodes');
class CLIENT_ERROR extends Error {
constructor(status, message = DEFAULT_MESSAGES.CLIENT_ERROR, ...args) {
super(message, ...args);
this.status = status || HTTP_STATUS_CODES.BAD_REQUEST;
}
}
class CLIENT_BAD_REQUEST extends CLIENT_ERROR {
constructor(message = DEFAULT_MESSAGES.CLIENT_BAD_REQUEST, ...args) {
super(HTTP_STATUS_CODES.BAD_REQUEST, message, ...args);
Error.captureStackTrace(this, CLIENT_BAD_REQUEST);
}
}
class CLIENT_UNAUTHORIZED extends CLIENT_ERROR {
constructor(message = DEFAULT_MESSAGES.CLIENT_UNATHORIZED, ...args) {
super(HTTP_STATUS_CODES.UNAUTHORIZED, message, ...args);
Error.captureStackTrace(this, CLIENT_UNAUTHORIZED);
}
}
class CLIENT_INVALID_TOKEN extends CLIENT_ERROR {
constructor(message = DEFAULT_MESSAGES.CLIENT_INVALID_TOKEN, ...args) {
super(HTTP_STATUS_CODES.UNAUTHORIZED, message, ...args);
Error.captureStackTrace(this, CLIENT_INVALID_TOKEN);
}
}
class CLIENT_FORBIDDEN extends CLIENT_ERROR {
constructor(message = DEFAULT_MESSAGES.CLIENT_FORBIDEN, ...args) {
super(HTTP_STATUS_CODES.FORBIDDEN, message, ...args);
Error.captureStackTrace(this, CLIENT_FORBIDDEN);
}
}
class NOT_FOUND extends CLIENT_ERROR {
constructor(message = DEFAULT_MESSAGES.NOT_FOUND, ...args) {
super(HTTP_STATUS_CODES.NOT_FOUND, message, ...args);
Error.captureStackTrace(this, NOT_FOUND);
}
}
module.exports = {
CLIENT_BAD_REQUEST,
CLIENT_ERROR,
CLIENT_FORBIDDEN,
CLIENT_INVALID_TOKEN,
CLIENT_UNAUTHORIZED,
NOT_FOUND
};