-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.js
72 lines (58 loc) · 1.31 KB
/
errors.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class AppError extends Error {
constructor (message) {
super(message);
this.name = '';
this.code = 0;
}
}
class BadRequestError extends AppError {
constructor (message) {
super(message || 'Bad Request');
this.name = 'BadRequestError';
this.code = 400;
}
}
class NotFoundError extends AppError {
constructor (message) {
super(message || 'Not Found');
this.name = 'NotFoundError';
this.code = 404;
}
}
class MethodNotAllowedError extends AppError {
constructor (message) {
super(message || 'Method Not Allowed');
this.name = 'MethodNotAllowedError';
this.code = 405;
}
}
class TeapotError extends AppError {
constructor (message) {
super(message || 'I\'m a teapot');
this.name = 'TeapotError';
this.code = 418;
}
}
class UnprocessableEntityError extends AppError {
constructor (message) {
super(message || 'Unprocessable Entity');
this.name = 'UnprocessableEntityError';
this.code = 422;
}
}
class InternalServerError extends AppError {
constructor (message) {
super(message || 'Internal Server Error');
this.name = 'InternalServerError';
this.code = 500;
}
}
module.exports = {
AppError,
BadRequestError,
NotFoundError,
MethodNotAllowedError,
TeapotError,
UnprocessableEntityError,
InternalServerError,
};