-
Notifications
You must be signed in to change notification settings - Fork 0
/
expressError.js
53 lines (43 loc) · 1008 Bytes
/
expressError.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
/** ExpressError extends normal JS error so we can
* add a status when we make an instance of it.
*
* The error-handling middleware will return this.
*/
class ExpressError extends Error {
constructor(message, status) {
super();
this.message = message;
this.status = status;
}
}
/** 404 NOT FOUND error. */
class NotFoundError extends ExpressError {
constructor(message = "Not Found") {
super(message, 404);
}
}
/** 401 UNAUTHORIZED error. */
class UnauthorizedError extends ExpressError {
constructor(message = "Unauthorized") {
super(message, 401);
}
}
/** 400 BAD REQUEST error. */
class BadRequestError extends ExpressError {
constructor(message = "Bad Request") {
super(message, 400);
}
}
/** 403 BAD REQUEST error. */
class ForbiddenError extends ExpressError {
constructor(message = "Bad Request") {
super(message, 403);
}
}
module.exports = {
ExpressError,
NotFoundError,
UnauthorizedError,
BadRequestError,
ForbiddenError,
};