@tryghost/mw-error-handler 0.2.0 → 0.2.3

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.
@@ -8,12 +8,12 @@ const tpl = require('@tryghost/tpl');
8
8
  const messages = {
9
9
  pageNotFound: 'Page not found',
10
10
  resourceNotFound: 'Resource not found',
11
- methodNotAcceptableVersionBehind: {
11
+ methodNotAcceptableVersionAhead: {
12
12
  message: 'Request not acceptable for provided Accept-Version header.',
13
13
  context: 'Provided client version {acceptVersion} is ahead of current Ghost instance version {ghostVersion}.',
14
14
  help: 'Upgrade your Ghost instance.'
15
15
  },
16
- methodNotAcceptableVersionAhead: {
16
+ methodNotAcceptableVersionBehind: {
17
17
  message: 'Request not acceptable for provided Accept-Version header.',
18
18
  context: 'Provided client version {acceptVersion} is outdated and is behind current Ghost version {ghostVersion}.',
19
19
  help: 'Upgrade your Ghost API client.'
@@ -130,6 +130,7 @@ const jsonErrorRendererV2 = (err, req, res, next) => { // eslint-disable-line no
130
130
  help: err.help || null,
131
131
  code: err.code || null,
132
132
  id: err.id || null
133
+ // @TODO: add ghostErrorCode here in a major (I thought V2 was for the V2 api, but it's actually the newer/correct handler)
133
134
  }]
134
135
  });
135
136
  };
@@ -193,32 +194,34 @@ module.exports.resourceNotFound = (req, res, next) => {
193
194
  semver.coerce(res.locals.safeVersion)
194
195
  );
195
196
 
196
- let errorOptions;
197
+ let notAcceptableError;
197
198
  if (versionComparison === 1) {
198
- errorOptions = {
199
+ notAcceptableError = new errors.RequestNotAcceptableError({
199
200
  message: tpl(
200
- messages.methodNotAcceptableVersionBehind.message
201
+ messages.methodNotAcceptableVersionAhead.message
201
202
  ),
202
- context: tpl(messages.methodNotAcceptableVersionBehind.context, {
203
+ context: tpl(messages.methodNotAcceptableVersionAhead.context, {
203
204
  acceptVersion: req.headers['accept-version'],
204
205
  ghostVersion: `v${res.locals.safeVersion}`
205
206
  }),
206
- help: tpl(messages.methodNotAcceptableVersionBehind.help)
207
- };
207
+ help: tpl(messages.methodNotAcceptableVersionAhead.help),
208
+ code: 'UPDATE_GHOST'
209
+ });
208
210
  } else {
209
- errorOptions = {
211
+ notAcceptableError = new errors.RequestNotAcceptableError({
210
212
  message: tpl(
211
- messages.methodNotAcceptableVersionAhead.message
213
+ messages.methodNotAcceptableVersionBehind.message
212
214
  ),
213
- context: tpl(messages.methodNotAcceptableVersionAhead.context, {
215
+ context: tpl(messages.methodNotAcceptableVersionBehind.context, {
214
216
  acceptVersion: req.headers['accept-version'],
215
217
  ghostVersion: `v${res.locals.safeVersion}`
216
218
  }),
217
- help: tpl(messages.methodNotAcceptableVersionAhead.help)
218
- };
219
+ help: tpl(messages.methodNotAcceptableVersionBehind.help),
220
+ code: 'UPDATE_CLIENT'
221
+ });
219
222
  }
220
223
 
221
- next(new errors.RequestNotAcceptableError(errorOptions));
224
+ next(notAcceptableError);
222
225
  } else {
223
226
  next(new errors.NotFoundError({message: tpl(messages.resourceNotFound)}));
224
227
  }
@@ -228,6 +231,9 @@ module.exports.pageNotFound = (req, res, next) => {
228
231
  next(new errors.NotFoundError({message: tpl(messages.pageNotFound)}));
229
232
  };
230
233
 
234
+ /**
235
+ * @deprecated: not used as of Ghost v5 and should be removed in a major bump
236
+ */
231
237
  module.exports.handleJSONResponse = sentry => [
232
238
  // Make sure the error can be served
233
239
  module.exports.prepareError,
@@ -239,6 +245,10 @@ module.exports.handleJSONResponse = sentry => [
239
245
  jsonErrorRenderer
240
246
  ];
241
247
 
248
+ /**
249
+ * @deprecated with above
250
+ * @TODO: rename this without the v2 in a major bump
251
+ */
242
252
  module.exports.handleJSONResponseV2 = sentry => [
243
253
  // Make sure the error can be served
244
254
  module.exports.prepareError,
@@ -258,4 +268,3 @@ module.exports.handleHTMLResponse = sentry => [
258
268
  // Format the stack for the user
259
269
  module.exports.prepareStack
260
270
  ];
261
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mw-error-handler",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "repository": "https://github.com/TryGhost/Utils/tree/main/packages/mw-error-handler",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -19,17 +19,17 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
- "c8": "7.11.0",
23
- "mocha": "9.1.3",
22
+ "c8": "7.11.2",
23
+ "mocha": "10.0.0",
24
24
  "should": "13.2.3",
25
- "sinon": "12.0.1"
25
+ "sinon": "13.0.2"
26
26
  },
27
27
  "dependencies": {
28
28
  "@tryghost/debug": "^0.1.9",
29
- "@tryghost/errors": "1.2.10",
29
+ "@tryghost/errors": "1.2.12",
30
30
  "@tryghost/tpl": "^0.1.8",
31
31
  "lodash": "^4.17.21",
32
32
  "semver": "^7.3.6"
33
33
  },
34
- "gitHead": "c2b9000721dc2113cf3338db58a139da3bb37fb0"
34
+ "gitHead": "e14f269ad87fee8f5c7c9fa6c2bc69d587f26e38"
35
35
  }