@tryghost/mw-error-handler 0.1.3 → 0.1.6
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/mw-error-handler.js +20 -5
- package/package.json +5 -3
package/lib/mw-error-handler.js
CHANGED
|
@@ -36,7 +36,8 @@ const messages = {
|
|
|
36
36
|
HostLimitError: 'Host Limit error, cannot {action}.',
|
|
37
37
|
DisabledFeatureError: 'Theme validation error, the {{{helperName}}} helper is not available. Cannot {action}.',
|
|
38
38
|
UpdateCollisionError: 'Saving failed! Someone else is editing this post.'
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
UnknownError: 'Unknown error - {name}, cannot {action}.'
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -78,8 +79,6 @@ module.exports.prepareError = (err, req, res, next) => {
|
|
|
78
79
|
// alternative for res.status();
|
|
79
80
|
res.statusCode = err.statusCode;
|
|
80
81
|
|
|
81
|
-
prepareStackForUser(err);
|
|
82
|
-
|
|
83
82
|
// never cache errors
|
|
84
83
|
res.set({
|
|
85
84
|
'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
|
@@ -88,6 +87,12 @@ module.exports.prepareError = (err, req, res, next) => {
|
|
|
88
87
|
next(err);
|
|
89
88
|
};
|
|
90
89
|
|
|
90
|
+
module.exports.prepareStack = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
|
91
|
+
const clonedError = prepareStackForUser(err);
|
|
92
|
+
|
|
93
|
+
next(clonedError);
|
|
94
|
+
};
|
|
95
|
+
|
|
91
96
|
const jsonErrorRenderer = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
|
92
97
|
res.json({
|
|
93
98
|
errors: [{
|
|
@@ -157,7 +162,11 @@ const prepareUserMessage = (err, req) => {
|
|
|
157
162
|
userError.context = err.message;
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
|
|
165
|
+
if (_.get(messages.userMessages, err.name)) {
|
|
166
|
+
userError.message = tpl(messages.userMessages[err.name], {action: action});
|
|
167
|
+
} else {
|
|
168
|
+
userError.message = tpl(messages.UnknownError, {action, name: err.name});
|
|
169
|
+
}
|
|
161
170
|
}
|
|
162
171
|
}
|
|
163
172
|
|
|
@@ -177,6 +186,8 @@ module.exports.handleJSONResponse = sentry => [
|
|
|
177
186
|
module.exports.prepareError,
|
|
178
187
|
// Handle the error in Sentry
|
|
179
188
|
sentry.errorHandler,
|
|
189
|
+
// Format the stack for the user
|
|
190
|
+
module.exports.prepareStack,
|
|
180
191
|
// Render the error using JSON format
|
|
181
192
|
jsonErrorRenderer
|
|
182
193
|
];
|
|
@@ -186,6 +197,8 @@ module.exports.handleJSONResponseV2 = sentry => [
|
|
|
186
197
|
module.exports.prepareError,
|
|
187
198
|
// Handle the error in Sentry
|
|
188
199
|
sentry.errorHandler,
|
|
200
|
+
// Format the stack for the user
|
|
201
|
+
module.exports.prepareStack,
|
|
189
202
|
// Render the error using JSON format
|
|
190
203
|
jsonErrorRendererV2
|
|
191
204
|
];
|
|
@@ -194,6 +207,8 @@ module.exports.handleHTMLResponse = sentry => [
|
|
|
194
207
|
// Make sure the error can be served
|
|
195
208
|
module.exports.prepareError,
|
|
196
209
|
// Handle the error in Sentry
|
|
197
|
-
sentry.errorHandler
|
|
210
|
+
sentry.errorHandler,
|
|
211
|
+
// Format the stack for the user
|
|
212
|
+
module.exports.prepareStack
|
|
198
213
|
];
|
|
199
214
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mw-error-handler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"repository": "https://github.com/TryGhost/Utils/tree/main/packages/mw-error-handler",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/debug": "^0.1.9",
|
|
29
|
-
"@tryghost/
|
|
29
|
+
"@tryghost/errors": "1.2.5",
|
|
30
|
+
"@tryghost/tpl": "^0.1.8",
|
|
31
|
+
"lodash": "4.17.21"
|
|
30
32
|
},
|
|
31
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "02581faa5be4812fb49e7944dacabef383c71074"
|
|
32
34
|
}
|