-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patherror.js
56 lines (47 loc) · 1.32 KB
/
error.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
class AppError extends Error {
statusCode;
constructor(name, statusCode, message) {
super(message);
this.name = name;
this.statusCode = statusCode;
}
}
class UserNotFoundError extends AppError {
constructor(message = 'User not found') {
super('USER_NOT_FOUND', 404, message);
}
}
class UserAlreadyExistsError extends AppError {
constructor(message = 'User already exists') {
super('USER_ALREADY_EXISTS', 409, message);
}
}
class InvalidCredentialsError extends AppError {
constructor(message = 'Invalid credentials') {
super('INVALID_CREDENTIALS', 401, message);
}
}
class RequiredTokenError extends AppError {
constructor(message = 'Missing token') {
super('REQUIRED_TOKEN', 400, message);
}
}
class AuthenticationRequiredError extends AppError {
constructor(message = 'Authentication required') {
super('AUTHENTICATION_REQUIRED', 401, message);
}
}
class AuthorizationError extends AppError {
constructor(message = 'You are not authorized to perform this action') {
super('UNAUTHORIZED', 403, message);
}
}
module.exports = {
AppError,
UserNotFoundError,
UserAlreadyExistsError,
InvalidCredentialsError,
RequiredTokenError,
AuthenticationRequiredError,
AuthorizationError,
};