@tryghost/mw-error-handler 0.2.2 → 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.
@@ -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,9 +194,9 @@ 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
201
  messages.methodNotAcceptableVersionAhead.message
201
202
  ),
@@ -205,9 +206,9 @@ module.exports.resourceNotFound = (req, res, next) => {
205
206
  }),
206
207
  help: tpl(messages.methodNotAcceptableVersionAhead.help),
207
208
  code: 'UPDATE_GHOST'
208
- };
209
+ });
209
210
  } else {
210
- errorOptions = {
211
+ notAcceptableError = new errors.RequestNotAcceptableError({
211
212
  message: tpl(
212
213
  messages.methodNotAcceptableVersionBehind.message
213
214
  ),
@@ -217,10 +218,10 @@ module.exports.resourceNotFound = (req, res, next) => {
217
218
  }),
218
219
  help: tpl(messages.methodNotAcceptableVersionBehind.help),
219
220
  code: 'UPDATE_CLIENT'
220
- };
221
+ });
221
222
  }
222
223
 
223
- next(new errors.RequestNotAcceptableError(errorOptions));
224
+ next(notAcceptableError);
224
225
  } else {
225
226
  next(new errors.NotFoundError({message: tpl(messages.resourceNotFound)}));
226
227
  }
@@ -230,6 +231,9 @@ module.exports.pageNotFound = (req, res, next) => {
230
231
  next(new errors.NotFoundError({message: tpl(messages.pageNotFound)}));
231
232
  };
232
233
 
234
+ /**
235
+ * @deprecated: not used as of Ghost v5 and should be removed in a major bump
236
+ */
233
237
  module.exports.handleJSONResponse = sentry => [
234
238
  // Make sure the error can be served
235
239
  module.exports.prepareError,
@@ -241,6 +245,10 @@ module.exports.handleJSONResponse = sentry => [
241
245
  jsonErrorRenderer
242
246
  ];
243
247
 
248
+ /**
249
+ * @deprecated with above
250
+ * @TODO: rename this without the v2 in a major bump
251
+ */
244
252
  module.exports.handleJSONResponseV2 = sentry => [
245
253
  // Make sure the error can be served
246
254
  module.exports.prepareError,
@@ -260,4 +268,3 @@ module.exports.handleHTMLResponse = sentry => [
260
268
  // Format the stack for the user
261
269
  module.exports.prepareStack
262
270
  ];
263
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mw-error-handler",
3
- "version": "0.2.2",
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",
@@ -20,9 +20,9 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "c8": "7.11.2",
23
- "mocha": "9.1.3",
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",
@@ -31,5 +31,5 @@
31
31
  "lodash": "^4.17.21",
32
32
  "semver": "^7.3.6"
33
33
  },
34
- "gitHead": "9a90e404200df76c6e4e3056f89d73eb69c9013e"
34
+ "gitHead": "e14f269ad87fee8f5c7c9fa6c2bc69d587f26e38"
35
35
  }