@tryghost/errors 1.1.0 → 1.2.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2021 Ghost Foundation
3
+ Copyright (c) 2013-2022 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -36,4 +36,4 @@ Follow the instructions for the top-level repo.
36
36
 
37
37
  # Copyright & License
38
38
 
39
- Copyright (c) 2013-2021 Ghost Foundation - Released under the [MIT license](LICENSE).
39
+ Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
package/lib/errors.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const uuid = require('uuid');
2
2
  const merge = require('lodash/merge');
3
3
  const isString = require('lodash/isString');
4
- const cloneDeep = require('lodash/cloneDeep');
5
4
  const utils = require('./utils');
6
5
 
7
6
  class GhostError extends Error {
@@ -71,34 +70,6 @@ class GhostError extends Error {
71
70
  });
72
71
  }
73
72
  }
74
-
75
- prepareErrorForUser() {
76
- const error = cloneDeep(this);
77
-
78
- let stackbits = error.stack.split(/\n/);
79
-
80
- // We build this up backwards, so we always insert at position 1
81
-
82
- if (process.env.NODE_ENV === 'production') {
83
- stackbits.splice(1, stackbits.length - 1);
84
- } else {
85
- // Clearly mark the strack trace
86
- stackbits.splice(1, 0, `Stack Trace:`);
87
- }
88
-
89
- // Add in our custom cotext and help methods
90
-
91
- if (this.help) {
92
- stackbits.splice(1, 0, `${this.help}`);
93
- }
94
-
95
- if (this.context) {
96
- stackbits.splice(1, 0, `${this.context}`);
97
- }
98
-
99
- error.stack = stackbits.join('\n');
100
- return error;
101
- }
102
73
  }
103
74
 
104
75
  const ghostErrors = {
@@ -332,6 +303,14 @@ const ghostErrors = {
332
303
  hideStack: true
333
304
  }, options));
334
305
  }
306
+ },
307
+ ConflictError: class ConflictError extends GhostError {
308
+ constructor(options) {
309
+ super(merge({
310
+ errorType: 'ConflictError',
311
+ statusCode: 409
312
+ }, options));
313
+ }
335
314
  }
336
315
  };
337
316
 
@@ -341,5 +320,6 @@ const ghostErrorsWithBase = Object.assign({}, ghostErrors, {GhostError});
341
320
  module.exports.utils = {
342
321
  serialize: utils.serialize.bind(ghostErrorsWithBase),
343
322
  deserialize: utils.deserialize.bind(ghostErrorsWithBase),
344
- isGhostError: utils.isGhostError.bind(ghostErrorsWithBase)
323
+ isGhostError: utils.isGhostError.bind(ghostErrorsWithBase),
324
+ prepareStackForUser: utils.prepareStackForUser
345
325
  };
package/lib/utils.js CHANGED
@@ -183,6 +183,36 @@ exports.deserialize = function deserialize(errorFormat) {
183
183
  return internalError;
184
184
  };
185
185
 
186
+ /**
187
+ * @description Replace the stack with a user-facing one
188
+ * @params {Error} err
189
+ */
190
+ exports.prepareStackForUser = function prepareStackForUser(error) {
191
+ let stackbits = error.stack.split(/\n/);
192
+
193
+ // We build this up backwards, so we always insert at position 1
194
+
195
+ if (process.env.NODE_ENV === 'production') {
196
+ stackbits.splice(1, stackbits.length - 1);
197
+ } else {
198
+ // Clearly mark the strack trace
199
+ stackbits.splice(1, 0, `Stack Trace:`);
200
+ }
201
+
202
+ // Add in our custom cotext and help methods
203
+
204
+ if (this.help) {
205
+ stackbits.splice(1, 0, `${this.help}`);
206
+ }
207
+
208
+ if (this.context) {
209
+ stackbits.splice(1, 0, `${this.context}`);
210
+ }
211
+
212
+ error.stack = stackbits.join('\n');
213
+ return error;
214
+ };
215
+
186
216
  /**
187
217
  * @description Check whether an error instance is a GhostError.
188
218
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tryghost/errors",
3
- "version": "1.1.0",
4
- "repository": "https://github.com/TryGhost/Utils/tree/main/packages/errors",
3
+ "version": "1.2.2",
4
+ "repository": "https://github.com/TryGhost/framework/tree/main/packages/errors",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
@@ -19,14 +19,14 @@
19
19
  "access": "public"
20
20
  },
21
21
  "devDependencies": {
22
- "c8": "7.10.0",
23
- "mocha": "9.1.3",
22
+ "c8": "7.11.0",
23
+ "mocha": "9.2.0",
24
24
  "should": "13.2.3",
25
- "sinon": "11.1.2"
25
+ "sinon": "13.0.1"
26
26
  },
27
27
  "dependencies": {
28
28
  "lodash": "^4.17.21",
29
29
  "uuid": "^8.3.2"
30
30
  },
31
- "gitHead": "4e480d2c089b3896a1fe51545b9853bc4163c38f"
31
+ "gitHead": "e954893434fda3f8c8de1970aaaa6f6a8b297f5d"
32
32
  }