@tryghost/errors 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/errors.js +22 -26
- package/lib/utils.js +14 -21
- package/package.json +3 -3
package/lib/errors.js
CHANGED
|
@@ -4,9 +4,7 @@ const isString = require('lodash/isString');
|
|
|
4
4
|
const utils = require('./utils');
|
|
5
5
|
|
|
6
6
|
class GhostError extends Error {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
options = options || {};
|
|
9
|
-
|
|
7
|
+
constructor(options = {}) {
|
|
10
8
|
super();
|
|
11
9
|
|
|
12
10
|
/**
|
|
@@ -34,7 +32,7 @@ class GhostError extends Error {
|
|
|
34
32
|
this.redirect = options.redirect || null;
|
|
35
33
|
|
|
36
34
|
this.message = options.message || this.message;
|
|
37
|
-
this.hideStack = options.hideStack;
|
|
35
|
+
this.hideStack = options.hideStack || false;
|
|
38
36
|
|
|
39
37
|
// NOTE: Error to inherit from, override!
|
|
40
38
|
// Nested objects are getting copied over in one piece (can be changed, but not needed right now)
|
|
@@ -52,16 +50,13 @@ class GhostError extends Error {
|
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
// CASE: `code` should put options as priority over err
|
|
55
|
-
if (property === 'code') {
|
|
53
|
+
if (property === 'code') {
|
|
56
54
|
// @ts-ignore
|
|
57
55
|
this[property] = this[property] || options.err[property];
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
if (property === 'stack') {
|
|
62
|
-
if (this.hideStack) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
59
|
+
if (property === 'stack' && !this.hideStack) {
|
|
65
60
|
this[property] = utils.wrapStack(this, options.err);
|
|
66
61
|
return;
|
|
67
62
|
}
|
|
@@ -206,7 +201,8 @@ const ghostErrors = {
|
|
|
206
201
|
constructor(options) {
|
|
207
202
|
super(merge({
|
|
208
203
|
statusCode: 500,
|
|
209
|
-
errorType: 'DataExportError'
|
|
204
|
+
errorType: 'DataExportError',
|
|
205
|
+
message: 'The server encountered an error whilst exporting data.'
|
|
210
206
|
}, options));
|
|
211
207
|
}
|
|
212
208
|
},
|
|
@@ -214,16 +210,8 @@ const ghostErrors = {
|
|
|
214
210
|
constructor(options) {
|
|
215
211
|
super(merge({
|
|
216
212
|
statusCode: 500,
|
|
217
|
-
errorType: 'DataImportError'
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
DatabaseVersionError: class DatabaseVersionError extends GhostError {
|
|
222
|
-
constructor(options) {
|
|
223
|
-
super(merge({
|
|
224
|
-
hideStack: true,
|
|
225
|
-
statusCode: 500,
|
|
226
|
-
errorType: 'DatabaseVersionError'
|
|
213
|
+
errorType: 'DataImportError',
|
|
214
|
+
message: 'The server encountered an error whilst importing data.'
|
|
227
215
|
}, options));
|
|
228
216
|
}
|
|
229
217
|
},
|
|
@@ -231,7 +219,8 @@ const ghostErrors = {
|
|
|
231
219
|
constructor(options) {
|
|
232
220
|
super(merge({
|
|
233
221
|
statusCode: 500,
|
|
234
|
-
errorType: 'EmailError'
|
|
222
|
+
errorType: 'EmailError',
|
|
223
|
+
message: 'The server encountered an error whilst sending email.'
|
|
235
224
|
}, options));
|
|
236
225
|
}
|
|
237
226
|
},
|
|
@@ -240,6 +229,7 @@ const ghostErrors = {
|
|
|
240
229
|
super(merge({
|
|
241
230
|
statusCode: 422,
|
|
242
231
|
errorType: 'ThemeValidationError',
|
|
232
|
+
message: 'The theme has a validation error.',
|
|
243
233
|
errorDetails: {}
|
|
244
234
|
}, options));
|
|
245
235
|
}
|
|
@@ -248,7 +238,8 @@ const ghostErrors = {
|
|
|
248
238
|
constructor(options) {
|
|
249
239
|
super(merge({
|
|
250
240
|
statusCode: 409,
|
|
251
|
-
errorType: 'DisabledFeatureError'
|
|
241
|
+
errorType: 'DisabledFeatureError',
|
|
242
|
+
message: 'Unable to complete the request, this feature is disabled.'
|
|
252
243
|
}, options));
|
|
253
244
|
}
|
|
254
245
|
},
|
|
@@ -256,7 +247,8 @@ const ghostErrors = {
|
|
|
256
247
|
constructor(options) {
|
|
257
248
|
super(merge({
|
|
258
249
|
statusCode: 409,
|
|
259
|
-
errorType: 'UpdateCollisionError'
|
|
250
|
+
errorType: 'UpdateCollisionError',
|
|
251
|
+
message: 'Unable to complete the request, there was a conflict.'
|
|
260
252
|
}, options));
|
|
261
253
|
}
|
|
262
254
|
},
|
|
@@ -265,7 +257,8 @@ const ghostErrors = {
|
|
|
265
257
|
super(merge({
|
|
266
258
|
errorType: 'HostLimitError',
|
|
267
259
|
hideStack: true,
|
|
268
|
-
statusCode: 403
|
|
260
|
+
statusCode: 403,
|
|
261
|
+
message: 'Unable to complete the request, this resource is limited.'
|
|
269
262
|
}, options));
|
|
270
263
|
}
|
|
271
264
|
},
|
|
@@ -273,7 +266,9 @@ const ghostErrors = {
|
|
|
273
266
|
constructor(options) {
|
|
274
267
|
super(merge({
|
|
275
268
|
errorType: 'HelperWarning',
|
|
276
|
-
hideStack: true
|
|
269
|
+
hideStack: true,
|
|
270
|
+
statusCode: 400,
|
|
271
|
+
message: 'A theme helper has done something unexpected.'
|
|
277
272
|
}, options));
|
|
278
273
|
}
|
|
279
274
|
},
|
|
@@ -308,7 +303,8 @@ const ghostErrors = {
|
|
|
308
303
|
constructor(options) {
|
|
309
304
|
super(merge({
|
|
310
305
|
errorType: 'ConflictError',
|
|
311
|
-
statusCode: 409
|
|
306
|
+
statusCode: 409,
|
|
307
|
+
message: 'The server has encountered an conflict.'
|
|
312
308
|
}, options));
|
|
313
309
|
}
|
|
314
310
|
}
|
package/lib/utils.js
CHANGED
|
@@ -27,21 +27,15 @@ _private.serialize = function serialize(err) {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
_private.deserialize = function deserialize(obj) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
} catch (err) {
|
|
41
|
-
return {
|
|
42
|
-
message: 'Something went wrong.'
|
|
43
|
-
};
|
|
44
|
-
}
|
|
30
|
+
return {
|
|
31
|
+
id: obj.id,
|
|
32
|
+
message: obj.detail || obj.error_description || obj.message,
|
|
33
|
+
statusCode: obj.status,
|
|
34
|
+
code: obj.code || obj.error,
|
|
35
|
+
level: obj.meta && obj.meta.level,
|
|
36
|
+
help: obj.meta && obj.meta.help,
|
|
37
|
+
context: obj.meta && obj.meta.context
|
|
38
|
+
};
|
|
45
39
|
};
|
|
46
40
|
|
|
47
41
|
/**
|
|
@@ -200,13 +194,12 @@ exports.prepareStackForUser = function prepareStackForUser(error) {
|
|
|
200
194
|
}
|
|
201
195
|
|
|
202
196
|
// Add in our custom cotext and help methods
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
stackbits.splice(1, 0, `${this.help}`);
|
|
197
|
+
if (error.help) {
|
|
198
|
+
stackbits.splice(1, 0, `${error.help}`);
|
|
206
199
|
}
|
|
207
200
|
|
|
208
|
-
if (
|
|
209
|
-
stackbits.splice(1, 0, `${
|
|
201
|
+
if (error.context) {
|
|
202
|
+
stackbits.splice(1, 0, `${error.context}`);
|
|
210
203
|
}
|
|
211
204
|
|
|
212
205
|
error.stack = stackbits.join('\n');
|
|
@@ -234,4 +227,4 @@ exports.isGhostError = function isGhostError(err) {
|
|
|
234
227
|
};
|
|
235
228
|
|
|
236
229
|
return recursiveIsGhostError(err.constructor);
|
|
237
|
-
};
|
|
230
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/errors",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"repository": "https://github.com/TryGhost/framework/tree/main/packages/errors",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura
|
|
10
|
+
"test": "NODE_ENV=testing c8 --check-coverage --all --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
11
11
|
"lint": "eslint . --ext .js --cache",
|
|
12
12
|
"posttest": "yarn lint"
|
|
13
13
|
},
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"uuid": "^8.3.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3768b2b29fe5c2ae4e535264246bc78933eba372"
|
|
32
32
|
}
|