@tryghost/mw-error-handler 0.2.3 → 1.0.1
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 +9 -40
- package/package.json +4 -4
package/lib/mw-error-handler.js
CHANGED
|
@@ -9,14 +9,14 @@ const messages = {
|
|
|
9
9
|
pageNotFound: 'Page not found',
|
|
10
10
|
resourceNotFound: 'Resource not found',
|
|
11
11
|
methodNotAcceptableVersionAhead: {
|
|
12
|
-
message: 'Request not
|
|
13
|
-
context: 'Provided client version {acceptVersion} is ahead of current Ghost
|
|
14
|
-
help: '
|
|
12
|
+
message: 'Request could not be served, the endpoint was not found.',
|
|
13
|
+
context: 'Provided client accept-version {acceptVersion} is ahead of current Ghost version {ghostVersion}.',
|
|
14
|
+
help: 'Try upgrading your Ghost install.'
|
|
15
15
|
},
|
|
16
16
|
methodNotAcceptableVersionBehind: {
|
|
17
|
-
message: 'Request not
|
|
18
|
-
context: 'Provided client version {acceptVersion} is
|
|
19
|
-
help: '
|
|
17
|
+
message: 'Request could not be served, the endpoint was not found.',
|
|
18
|
+
context: 'Provided client accept-version {acceptVersion} is behind current Ghost version {ghostVersion}.',
|
|
19
|
+
help: 'Try upgrading your Ghost API client.'
|
|
20
20
|
},
|
|
21
21
|
actions: {
|
|
22
22
|
images: {
|
|
@@ -105,32 +105,19 @@ module.exports.prepareStack = (err, req, res, next) => { // eslint-disable-line
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
const jsonErrorRenderer = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
|
108
|
-
res.json({
|
|
109
|
-
errors: [{
|
|
110
|
-
message: err.message,
|
|
111
|
-
context: err.context,
|
|
112
|
-
help: err.help,
|
|
113
|
-
errorType: err.errorType,
|
|
114
|
-
errorDetails: err.errorDetails,
|
|
115
|
-
ghostErrorCode: err.ghostErrorCode
|
|
116
|
-
}]
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const jsonErrorRendererV2 = (err, req, res, next) => { // eslint-disable-line no-unused-vars
|
|
121
108
|
const userError = prepareUserMessage(err, req);
|
|
122
109
|
|
|
123
110
|
res.json({
|
|
124
111
|
errors: [{
|
|
125
|
-
message: userError.message
|
|
112
|
+
message: userError.message,
|
|
126
113
|
context: userError.context || null,
|
|
127
114
|
type: err.errorType || null,
|
|
128
115
|
details: err.errorDetails || null,
|
|
129
116
|
property: err.property || null,
|
|
130
117
|
help: err.help || null,
|
|
131
118
|
code: err.code || null,
|
|
132
|
-
id: err.id || null
|
|
133
|
-
|
|
119
|
+
id: err.id || null,
|
|
120
|
+
ghostErrorCode: err.ghostErrorCode || null
|
|
134
121
|
}]
|
|
135
122
|
});
|
|
136
123
|
};
|
|
@@ -231,9 +218,6 @@ module.exports.pageNotFound = (req, res, next) => {
|
|
|
231
218
|
next(new errors.NotFoundError({message: tpl(messages.pageNotFound)}));
|
|
232
219
|
};
|
|
233
220
|
|
|
234
|
-
/**
|
|
235
|
-
* @deprecated: not used as of Ghost v5 and should be removed in a major bump
|
|
236
|
-
*/
|
|
237
221
|
module.exports.handleJSONResponse = sentry => [
|
|
238
222
|
// Make sure the error can be served
|
|
239
223
|
module.exports.prepareError,
|
|
@@ -245,21 +229,6 @@ module.exports.handleJSONResponse = sentry => [
|
|
|
245
229
|
jsonErrorRenderer
|
|
246
230
|
];
|
|
247
231
|
|
|
248
|
-
/**
|
|
249
|
-
* @deprecated with above
|
|
250
|
-
* @TODO: rename this without the v2 in a major bump
|
|
251
|
-
*/
|
|
252
|
-
module.exports.handleJSONResponseV2 = sentry => [
|
|
253
|
-
// Make sure the error can be served
|
|
254
|
-
module.exports.prepareError,
|
|
255
|
-
// Handle the error in Sentry
|
|
256
|
-
sentry.errorHandler,
|
|
257
|
-
// Format the stack for the user
|
|
258
|
-
module.exports.prepareStack,
|
|
259
|
-
// Render the error using JSON format
|
|
260
|
-
jsonErrorRendererV2
|
|
261
|
-
];
|
|
262
|
-
|
|
263
232
|
module.exports.handleHTMLResponse = sentry => [
|
|
264
233
|
// Make sure the error can be served
|
|
265
234
|
module.exports.prepareError,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mw-error-handler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"repository": "https://github.com/TryGhost/Utils/tree/main/packages/mw-error-handler",
|
|
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 --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
10
|
+
"test": "NODE_ENV=testing c8 --all --check-coverage --100 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
11
11
|
"lint": "eslint . --ext .js --cache",
|
|
12
12
|
"posttest": "yarn lint"
|
|
13
13
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"c8": "7.11.2",
|
|
23
23
|
"mocha": "10.0.0",
|
|
24
24
|
"should": "13.2.3",
|
|
25
|
-
"sinon": "
|
|
25
|
+
"sinon": "14.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tryghost/debug": "^0.1.9",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"semver": "^7.3.6"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "273e3f58cdce8874bd732ddc5a3fc0aad71e5a96"
|
|
35
35
|
}
|