-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (86 loc) · 2.76 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import statusCodes from "./statusCodes.js"
class CustomError extends Error {
constructor(message) {
super(message)
}
}
export class BAD_REQUEST_ERROR extends CustomError {
constructor(message) {
super(message)
this.name = 'BAD REQUEST ERROR'
this.stack = null
this.statusCode = statusCodes.BAD_REQUEST
}
}
export class UNAUTHORIZED_ERROR extends CustomError {
constructor(message) {
super(message)
this.name = 'UNAUTHORIZED ERROR'
this.stack = null
this.statusCode = statusCodes.UNAUTHORIZED
}
}
export class FORBIDDEN_ERROR extends CustomError {
constructor(message = "This content is restricted") {
super(message)
this.name = 'FORBIDDEN ERROR'
this.stack = null
this.statusCode = statusCodes.FORBIDDEN
}
}
export class NOT_FOUND_ERROR extends CustomError {
constructor(message = "Content not found") {
super(message)
this.name = 'NOT FOUND ERROR'
this.stack = null
this.statusCode = statusCodes.NOT_FOUND
}
}
export class METHOD_NOT_ALLOWED_ERROR extends CustomError {
constructor(message = "Unsopported operation") {
super(message)
this.name = 'METHOD NOT ALOWED'
this.stack = null
this.statusCode = statusCodes.METHOD_NOT_ALLOWED
}
}
export class TOO_MANY_REQUESTS_ERROR extends CustomError {
constructor(message = "Too many requests") {
super(message)
this.name = 'TOO MANY REQUEST ERROR'
this.stack = null
this.statusCode = statusCodes.TOO_MANY_REQUESTS
}
}
export class CONFLICT_ERROR extends CustomError {
constructor(message = "cannot be completed due to a conflict with the current state of the resource on the server. ") {
super(message)
this.name = 'CONFLICT ERROR'
this.stack = null
this.statusCode = statusCodes.CONFLICT
}
}
export class INTERNAL_SERVER_ERROR extends CustomError {
constructor(message = "An unexpected error occurred on the server") {
super(message)
this.name = 'INTERNAL SERVER ERROR'
this.stack = null
this.statusCode = statusCodes.INTERNAL_SERVER_ERROR
}
}
export class SERVICE_UNAVAILABLE_ERROR extends CustomError {
constructor(message = "Service is temporarily unavailable") {
super(message)
this.name = 'SERVICE UNAVAILABLE ERROR'
this.stack = null
this.statusCode = statusCodes.SERVICE_UNAVAILABLE
}
}
export class UNSUPPORTED_MEDIA_TYPE_ERROR extends CustomError {
constructor(message = "The media type is not supported") {
super(message)
this.name = 'UNSUPPORTED MEDIA TYPE ERROR'
this.stack = null
this.statusCode = statusCodes.UNSUPPORTED_MEDIA_TYPE
}
}