@tryghost/errors 1.0.4 → 1.1.0
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 +35 -2
- package/lib/utils.js +6 -0
- package/package.json +2 -2
package/lib/errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const uuid = require('uuid');
|
|
2
2
|
const merge = require('lodash/merge');
|
|
3
3
|
const isString = require('lodash/isString');
|
|
4
|
+
const cloneDeep = require('lodash/cloneDeep');
|
|
4
5
|
const utils = require('./utils');
|
|
5
6
|
|
|
6
7
|
class GhostError extends Error {
|
|
@@ -59,7 +60,10 @@ class GhostError extends Error {
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
if (property === 'stack') {
|
|
62
|
-
this
|
|
63
|
+
if (this.hideStack) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this[property] = utils.wrapStack(this, options.err);
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
65
69
|
|
|
@@ -67,6 +71,34 @@ class GhostError extends Error {
|
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
|
|
75
|
+
prepareErrorForUser() {
|
|
76
|
+
const error = cloneDeep(this);
|
|
77
|
+
|
|
78
|
+
let stackbits = error.stack.split(/\n/);
|
|
79
|
+
|
|
80
|
+
// We build this up backwards, so we always insert at position 1
|
|
81
|
+
|
|
82
|
+
if (process.env.NODE_ENV === 'production') {
|
|
83
|
+
stackbits.splice(1, stackbits.length - 1);
|
|
84
|
+
} else {
|
|
85
|
+
// Clearly mark the strack trace
|
|
86
|
+
stackbits.splice(1, 0, `Stack Trace:`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Add in our custom cotext and help methods
|
|
90
|
+
|
|
91
|
+
if (this.help) {
|
|
92
|
+
stackbits.splice(1, 0, `${this.help}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (this.context) {
|
|
96
|
+
stackbits.splice(1, 0, `${this.context}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
error.stack = stackbits.join('\n');
|
|
100
|
+
return error;
|
|
101
|
+
}
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
const ghostErrors = {
|
|
@@ -95,7 +127,8 @@ const ghostErrors = {
|
|
|
95
127
|
super(merge({
|
|
96
128
|
statusCode: 404,
|
|
97
129
|
errorType: 'NotFoundError',
|
|
98
|
-
message: 'Resource could not be found.'
|
|
130
|
+
message: 'Resource could not be found.',
|
|
131
|
+
hideStack: true
|
|
99
132
|
}, options));
|
|
100
133
|
}
|
|
101
134
|
},
|
package/lib/utils.js
CHANGED
|
@@ -127,6 +127,12 @@ _private.JSONAPIDeserialize = function JSONAPIDeserialize(errorFormat) {
|
|
|
127
127
|
return internalError;
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
exports.wrapStack = function wrapStack(err, internalErr) {
|
|
131
|
+
const extraLine = err.stack.split(/\n/g)[1];
|
|
132
|
+
const [firstLine, ...rest] = internalErr.stack.split(/\n/g);
|
|
133
|
+
return [firstLine, extraLine, ...rest].join('\n');
|
|
134
|
+
};
|
|
135
|
+
|
|
130
136
|
/**
|
|
131
137
|
* @description Serialize GhostError instance to error JSON format
|
|
132
138
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/errors",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/Utils/tree/main/packages/errors",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"uuid": "^8.3.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "4e480d2c089b3896a1fe51545b9853bc4163c38f"
|
|
32
32
|
}
|