-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
306 lines (260 loc) · 7.66 KB
/
index.ts
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
interface EsNextErrorOptions {
cause?: unknown
errors?: string[] | undefined
}
export interface ApiErrorOptions extends EsNextErrorOptions {
message: string
status: number
}
export class ApiError extends Error {
public status: number
public errors?: string[] | undefined
constructor({ message, cause, status, errors }: ApiErrorOptions) {
super()
this.message = message
this.cause = cause
this.status = status
this.errors = errors
this.name = 'ApiError'
}
public static badRequest(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 400, message, cause: options?.cause })
}
public static unauthorized(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 401, message, cause: options?.cause })
}
public static paymentRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 402, message, cause: options?.cause })
}
public static forbidden(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 403, message, cause: options?.cause })
}
public static notFound(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 404, message, cause: options?.cause })
}
public static methodNotAllowed(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 405, message, cause: options?.cause })
}
public static notAcceptable(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 406, message, cause: options?.cause })
}
public static proxyAuthenticationRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 407, message, cause: options?.cause })
}
public static requestTimeout(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 408, message, cause: options?.cause })
}
public static conflict(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 409, message, cause: options?.cause })
}
public static gone(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 410, message, cause: options?.cause })
}
public static lengthRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 411, message, cause: options?.cause })
}
public static preconditionFailed(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 412, message, cause: options?.cause })
}
public static payloadTooLarge(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 413, message, cause: options?.cause })
}
public static uriTooLong(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 414, message, cause: options?.cause })
}
public static unsupportedMediaType(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 415, message, cause: options?.cause })
}
public static rangeNotSatisfiable(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 416, message, cause: options?.cause })
}
public static expectationFailed(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 417, message, cause: options?.cause })
}
public static imaTeapot(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 418, message, cause: options?.cause })
}
public static misdirectedRequest(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 421, message, cause: options?.cause })
}
public static unprocessableEntity(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 422, message, cause: options?.cause })
}
public static locked(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 423, message, cause: options?.cause })
}
public static failedDependency(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 424, message, cause: options?.cause })
}
public static tooEarly(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 425, message, cause: options?.cause })
}
public static upgradeRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 426, message, cause: options?.cause })
}
public static preconditionRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 428, message, cause: options?.cause })
}
public static tooManyRequests(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 429, message, cause: options?.cause })
}
public static requestHeaderFieldsTooLarge(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 431, message, cause: options?.cause })
}
public static unavailableForLegalReasons(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 451, message, cause: options?.cause })
}
public static internalServerError(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 500, message, cause: options?.cause })
}
public static notImplemented(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 501, message, cause: options?.cause })
}
public static badGateway(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 502, message, cause: options?.cause })
}
public static serviceUnavailable(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 503, message, cause: options?.cause })
}
public static gatewayTimeout(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 504, message, cause: options?.cause })
}
public static httpVersionNotSupported(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 505, message, cause: options?.cause })
}
public static variantAlsoNegotiates(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 506, message, cause: options?.cause })
}
public static insufficientStorage(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 507, message, cause: options?.cause })
}
public static loopDetected(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 508, message, cause: options?.cause })
}
public static notExtended(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 510, message, cause: options?.cause })
}
public static networkAuthenticationRequired(
message: string,
options?: EsNextErrorOptions | undefined
) {
return new ApiError({ status: 511, message, cause: options?.cause })
}
}