@tryghost/mw-error-handler 0.2.2 → 1.0.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/mw-error-handler.js +15 -39
- package/package.json +5 -5
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,31 +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
|
|
119
|
+
id: err.id || null,
|
|
120
|
+
ghostErrorCode: err.ghostErrorCode || null
|
|
133
121
|
}]
|
|
134
122
|
});
|
|
135
123
|
};
|
|
@@ -193,9 +181,9 @@ module.exports.resourceNotFound = (req, res, next) => {
|
|
|
193
181
|
semver.coerce(res.locals.safeVersion)
|
|
194
182
|
);
|
|
195
183
|
|
|
196
|
-
let
|
|
184
|
+
let notAcceptableError;
|
|
197
185
|
if (versionComparison === 1) {
|
|
198
|
-
|
|
186
|
+
notAcceptableError = new errors.RequestNotAcceptableError({
|
|
199
187
|
message: tpl(
|
|
200
188
|
messages.methodNotAcceptableVersionAhead.message
|
|
201
189
|
),
|
|
@@ -205,9 +193,9 @@ module.exports.resourceNotFound = (req, res, next) => {
|
|
|
205
193
|
}),
|
|
206
194
|
help: tpl(messages.methodNotAcceptableVersionAhead.help),
|
|
207
195
|
code: 'UPDATE_GHOST'
|
|
208
|
-
};
|
|
196
|
+
});
|
|
209
197
|
} else {
|
|
210
|
-
|
|
198
|
+
notAcceptableError = new errors.RequestNotAcceptableError({
|
|
211
199
|
message: tpl(
|
|
212
200
|
messages.methodNotAcceptableVersionBehind.message
|
|
213
201
|
),
|
|
@@ -217,10 +205,10 @@ module.exports.resourceNotFound = (req, res, next) => {
|
|
|
217
205
|
}),
|
|
218
206
|
help: tpl(messages.methodNotAcceptableVersionBehind.help),
|
|
219
207
|
code: 'UPDATE_CLIENT'
|
|
220
|
-
};
|
|
208
|
+
});
|
|
221
209
|
}
|
|
222
210
|
|
|
223
|
-
next(
|
|
211
|
+
next(notAcceptableError);
|
|
224
212
|
} else {
|
|
225
213
|
next(new errors.NotFoundError({message: tpl(messages.resourceNotFound)}));
|
|
226
214
|
}
|
|
@@ -241,17 +229,6 @@ module.exports.handleJSONResponse = sentry => [
|
|
|
241
229
|
jsonErrorRenderer
|
|
242
230
|
];
|
|
243
231
|
|
|
244
|
-
module.exports.handleJSONResponseV2 = sentry => [
|
|
245
|
-
// Make sure the error can be served
|
|
246
|
-
module.exports.prepareError,
|
|
247
|
-
// Handle the error in Sentry
|
|
248
|
-
sentry.errorHandler,
|
|
249
|
-
// Format the stack for the user
|
|
250
|
-
module.exports.prepareStack,
|
|
251
|
-
// Render the error using JSON format
|
|
252
|
-
jsonErrorRendererV2
|
|
253
|
-
];
|
|
254
|
-
|
|
255
232
|
module.exports.handleHTMLResponse = sentry => [
|
|
256
233
|
// Make sure the error can be served
|
|
257
234
|
module.exports.prepareError,
|
|
@@ -260,4 +237,3 @@ module.exports.handleHTMLResponse = sentry => [
|
|
|
260
237
|
// Format the stack for the user
|
|
261
238
|
module.exports.prepareStack
|
|
262
239
|
];
|
|
263
|
-
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mw-error-handler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
},
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"c8": "7.11.2",
|
|
23
|
-
"mocha": "
|
|
23
|
+
"mocha": "10.0.0",
|
|
24
24
|
"should": "13.2.3",
|
|
25
|
-
"sinon": "
|
|
25
|
+
"sinon": "13.0.2"
|
|
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": "9bce5a81753e041e55b86f654c97924562eb7709"
|
|
35
35
|
}
|