-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
errors.ts
312 lines (280 loc) · 9.45 KB
/
errors.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
307
308
309
310
311
312
import {GhostError, GhostErrorOptions} from './GhostError';
const mergeOptions = (options: GhostErrorOptions, defaults: GhostErrorOptions) => {
const result = {...defaults};
// Ignore undefined options - for example passing statusCode: undefined should not override the default
(Object.keys(options) as (keyof GhostErrorOptions)[]).forEach((key) => {
if (options[key] !== undefined) {
result[key] = options[key];
}
});
return result;
};
export class InternalServerError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 500,
level: 'critical',
errorType: 'InternalServerError',
message: 'The server has encountered an error.'
}));
}
}
export class IncorrectUsageError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 400,
level: 'critical',
errorType: 'IncorrectUsageError',
message: 'We detected a misuse. Please read the stack trace.'
}));
}
}
export class NotFoundError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 404,
errorType: 'NotFoundError',
message: 'Resource could not be found.',
hideStack: true
}));
}
}
export class BadRequestError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 400,
errorType: 'BadRequestError',
message: 'The request could not be understood.'
}));
}
}
export class UnauthorizedError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 401,
errorType: 'UnauthorizedError',
message: 'You are not authorised to make this request.'
}));
}
}
export class NoPermissionError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 403,
errorType: 'NoPermissionError',
message: 'You do not have permission to perform this request.'
}));
}
}
export class ValidationError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 422,
errorType: 'ValidationError',
message: 'The request failed validation.'
}));
}
}
export class UnsupportedMediaTypeError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 415,
errorType: 'UnsupportedMediaTypeError',
message: 'The media in the request is not supported by the server.'
}));
}
}
export class TooManyRequestsError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 429,
errorType: 'TooManyRequestsError',
message: 'Server has received too many similar requests in a short space of time.'
}));
}
}
export class MaintenanceError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 503,
errorType: 'MaintenanceError',
message: 'The server is temporarily down for maintenance.'
}));
}
}
export class MethodNotAllowedError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 405,
errorType: 'MethodNotAllowedError',
message: 'Method not allowed for resource.'
}));
}
}
export class RequestNotAcceptableError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 406,
errorType: 'RequestNotAcceptableError',
message: 'Request not acceptable for provided Accept-Version header.',
hideStack: true
}));
}
}
export class RangeNotSatisfiableError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 416,
errorType: 'RangeNotSatisfiableError',
message: 'Range not satisfiable for provided Range header.',
hideStack: true
}));
}
}
export class RequestEntityTooLargeError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 413,
errorType: 'RequestEntityTooLargeError',
message: 'Request was too big for the server to handle.'
}));
}
}
export class TokenRevocationError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 503,
errorType: 'TokenRevocationError',
message: 'Token is no longer available.'
}));
}
}
export class VersionMismatchError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 400,
errorType: 'VersionMismatchError',
message: 'Requested version does not match server version.'
}));
}
}
export class DataExportError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: 'DataExportError',
message: 'The server encountered an error whilst exporting data.'
}));
}
}
export class DataImportError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: 'DataImportError',
message: 'The server encountered an error whilst importing data.'
}));
}
}
export class EmailError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 500,
errorType: 'EmailError',
message: 'The server encountered an error whilst sending email.'
}));
}
}
export class ThemeValidationError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 422,
errorType: 'ThemeValidationError',
message: 'The theme has a validation error.',
errorDetails: {}
}));
}
}
export class DisabledFeatureError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 409,
errorType: 'DisabledFeatureError',
message: 'Unable to complete the request, this feature is disabled.'
}));
}
}
export class UpdateCollisionError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
statusCode: 409,
errorType: 'UpdateCollisionError',
message: 'Unable to complete the request, there was a conflict.'
}));
}
}
export class HostLimitError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'HostLimitError',
hideStack: true,
statusCode: 403,
message: 'Unable to complete the request, this resource is limited.'
}));
}
}
export class HelperWarning extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'HelperWarning',
hideStack: true,
statusCode: 400,
message: 'A theme helper has done something unexpected.'
}));
}
}
export class PasswordResetRequiredError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'PasswordResetRequiredError',
statusCode: 401,
message: 'For security, you need to create a new password. An email has been sent to you with instructions!'
}));
}
}
export class UnhandledJobError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'UnhandledJobError',
message: 'Processed job threw an unhandled error',
level: 'critical'
}));
}
}
export class NoContentError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'NoContentError',
statusCode: 204,
hideStack: true
}));
}
}
export class ConflictError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'ConflictError',
statusCode: 409,
message: 'The server has encountered an conflict.'
}));
}
}
export class MigrationError extends GhostError {
constructor(options: GhostErrorOptions = {}) {
super(mergeOptions(options, {
errorType: 'MigrationError',
message: 'An error has occurred applying a database migration.',
level: 'critical'
}));
}
}