@tryghost/errors 1.2.26 → 1.3.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.
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ var GhostError_exports = {};
25
+ __export(GhostError_exports, {
26
+ GhostError: () => GhostError
27
+ });
28
+ module.exports = __toCommonJS(GhostError_exports);
29
+ var import_uuid = require("uuid");
30
+ var import_wrap_stack = require("./wrap-stack");
31
+ class GhostError extends Error {
32
+ constructor(options = {}) {
33
+ super();
34
+ __publicField(this, "statusCode");
35
+ __publicField(this, "errorType");
36
+ __publicField(this, "level");
37
+ __publicField(this, "id");
38
+ __publicField(this, "context");
39
+ __publicField(this, "help");
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ __publicField(this, "errorDetails");
42
+ __publicField(this, "code");
43
+ __publicField(this, "property");
44
+ __publicField(this, "redirect");
45
+ __publicField(this, "hideStack");
46
+ this.statusCode = 500;
47
+ this.errorType = "InternalServerError";
48
+ this.level = "normal";
49
+ this.message = "The server has encountered an error.";
50
+ this.id = (0, import_uuid.v1)();
51
+ this.id = options.id || this.id;
52
+ this.statusCode = options.statusCode || this.statusCode;
53
+ this.level = options.level || this.level;
54
+ this.context = options.context;
55
+ this.help = options.help;
56
+ this.errorType = this.name = options.errorType || this.errorType;
57
+ this.errorDetails = options.errorDetails;
58
+ this.code = options.code || null;
59
+ this.property = options.property || null;
60
+ this.redirect = options.redirect || null;
61
+ this.message = options.message || this.message;
62
+ this.hideStack = options.hideStack || false;
63
+ if (options.err) {
64
+ if (typeof options.err === "string") {
65
+ options.err = new Error(options.err);
66
+ }
67
+ Object.getOwnPropertyNames(options.err).forEach((property) => {
68
+ if (["errorType", "name", "statusCode", "message", "level"].indexOf(property) !== -1) {
69
+ return;
70
+ }
71
+ if (property === "code") {
72
+ this[property] = this[property] || options.err[property];
73
+ return;
74
+ }
75
+ if (property === "stack" && !this.hideStack) {
76
+ this[property] = (0, import_wrap_stack.wrapStack)(this, options.err);
77
+ return;
78
+ }
79
+ this[property] = options.err[property] || this[property];
80
+ });
81
+ }
82
+ }
83
+ }
package/cjs/errors.js ADDED
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ BadRequestError: () => BadRequestError,
22
+ ConflictError: () => ConflictError,
23
+ DataExportError: () => DataExportError,
24
+ DataImportError: () => DataImportError,
25
+ DisabledFeatureError: () => DisabledFeatureError,
26
+ EmailError: () => EmailError,
27
+ HelperWarning: () => HelperWarning,
28
+ HostLimitError: () => HostLimitError,
29
+ IncorrectUsageError: () => IncorrectUsageError,
30
+ InternalServerError: () => InternalServerError,
31
+ MaintenanceError: () => MaintenanceError,
32
+ MethodNotAllowedError: () => MethodNotAllowedError,
33
+ MigrationError: () => MigrationError,
34
+ NoContentError: () => NoContentError,
35
+ NoPermissionError: () => NoPermissionError,
36
+ NotFoundError: () => NotFoundError,
37
+ PasswordResetRequiredError: () => PasswordResetRequiredError,
38
+ RequestEntityTooLargeError: () => RequestEntityTooLargeError,
39
+ RequestNotAcceptableError: () => RequestNotAcceptableError,
40
+ ThemeValidationError: () => ThemeValidationError,
41
+ TokenRevocationError: () => TokenRevocationError,
42
+ TooManyRequestsError: () => TooManyRequestsError,
43
+ UnauthorizedError: () => UnauthorizedError,
44
+ UnhandledJobError: () => UnhandledJobError,
45
+ UnsupportedMediaTypeError: () => UnsupportedMediaTypeError,
46
+ UpdateCollisionError: () => UpdateCollisionError,
47
+ ValidationError: () => ValidationError,
48
+ VersionMismatchError: () => VersionMismatchError
49
+ });
50
+ module.exports = __toCommonJS(errors_exports);
51
+ var import_GhostError = require("./GhostError");
52
+ const mergeOptions = (options, defaults) => {
53
+ const result = { ...defaults };
54
+ Object.keys(options).forEach((key) => {
55
+ if (options[key] !== void 0) {
56
+ result[key] = options[key];
57
+ }
58
+ });
59
+ return result;
60
+ };
61
+ class InternalServerError extends import_GhostError.GhostError {
62
+ constructor(options = {}) {
63
+ super(mergeOptions(options, {
64
+ statusCode: 500,
65
+ level: "critical",
66
+ errorType: "InternalServerError",
67
+ message: "The server has encountered an error."
68
+ }));
69
+ }
70
+ }
71
+ class IncorrectUsageError extends import_GhostError.GhostError {
72
+ constructor(options = {}) {
73
+ super(mergeOptions(options, {
74
+ statusCode: 400,
75
+ level: "critical",
76
+ errorType: "IncorrectUsageError",
77
+ message: "We detected a misuse. Please read the stack trace."
78
+ }));
79
+ }
80
+ }
81
+ class NotFoundError extends import_GhostError.GhostError {
82
+ constructor(options = {}) {
83
+ super(mergeOptions(options, {
84
+ statusCode: 404,
85
+ errorType: "NotFoundError",
86
+ message: "Resource could not be found.",
87
+ hideStack: true
88
+ }));
89
+ }
90
+ }
91
+ class BadRequestError extends import_GhostError.GhostError {
92
+ constructor(options = {}) {
93
+ super(mergeOptions(options, {
94
+ statusCode: 400,
95
+ errorType: "BadRequestError",
96
+ message: "The request could not be understood."
97
+ }));
98
+ }
99
+ }
100
+ class UnauthorizedError extends import_GhostError.GhostError {
101
+ constructor(options = {}) {
102
+ super(mergeOptions(options, {
103
+ statusCode: 401,
104
+ errorType: "UnauthorizedError",
105
+ message: "You are not authorised to make this request."
106
+ }));
107
+ }
108
+ }
109
+ class NoPermissionError extends import_GhostError.GhostError {
110
+ constructor(options = {}) {
111
+ super(mergeOptions(options, {
112
+ statusCode: 403,
113
+ errorType: "NoPermissionError",
114
+ message: "You do not have permission to perform this request."
115
+ }));
116
+ }
117
+ }
118
+ class ValidationError extends import_GhostError.GhostError {
119
+ constructor(options = {}) {
120
+ super(mergeOptions(options, {
121
+ statusCode: 422,
122
+ errorType: "ValidationError",
123
+ message: "The request failed validation."
124
+ }));
125
+ }
126
+ }
127
+ class UnsupportedMediaTypeError extends import_GhostError.GhostError {
128
+ constructor(options = {}) {
129
+ super(mergeOptions(options, {
130
+ statusCode: 415,
131
+ errorType: "UnsupportedMediaTypeError",
132
+ message: "The media in the request is not supported by the server."
133
+ }));
134
+ }
135
+ }
136
+ class TooManyRequestsError extends import_GhostError.GhostError {
137
+ constructor(options = {}) {
138
+ super(mergeOptions(options, {
139
+ statusCode: 429,
140
+ errorType: "TooManyRequestsError",
141
+ message: "Server has received too many similar requests in a short space of time."
142
+ }));
143
+ }
144
+ }
145
+ class MaintenanceError extends import_GhostError.GhostError {
146
+ constructor(options = {}) {
147
+ super(mergeOptions(options, {
148
+ statusCode: 503,
149
+ errorType: "MaintenanceError",
150
+ message: "The server is temporarily down for maintenance."
151
+ }));
152
+ }
153
+ }
154
+ class MethodNotAllowedError extends import_GhostError.GhostError {
155
+ constructor(options = {}) {
156
+ super(mergeOptions(options, {
157
+ statusCode: 405,
158
+ errorType: "MethodNotAllowedError",
159
+ message: "Method not allowed for resource."
160
+ }));
161
+ }
162
+ }
163
+ class RequestNotAcceptableError extends import_GhostError.GhostError {
164
+ constructor(options = {}) {
165
+ super(mergeOptions(options, {
166
+ statusCode: 406,
167
+ errorType: "RequestNotAcceptableError",
168
+ message: "Request not acceptable for provided Accept-Version header.",
169
+ hideStack: true
170
+ }));
171
+ }
172
+ }
173
+ class RequestEntityTooLargeError extends import_GhostError.GhostError {
174
+ constructor(options = {}) {
175
+ super(mergeOptions(options, {
176
+ statusCode: 413,
177
+ errorType: "RequestEntityTooLargeError",
178
+ message: "Request was too big for the server to handle."
179
+ }));
180
+ }
181
+ }
182
+ class TokenRevocationError extends import_GhostError.GhostError {
183
+ constructor(options = {}) {
184
+ super(mergeOptions(options, {
185
+ statusCode: 503,
186
+ errorType: "TokenRevocationError",
187
+ message: "Token is no longer available."
188
+ }));
189
+ }
190
+ }
191
+ class VersionMismatchError extends import_GhostError.GhostError {
192
+ constructor(options = {}) {
193
+ super(mergeOptions(options, {
194
+ statusCode: 400,
195
+ errorType: "VersionMismatchError",
196
+ message: "Requested version does not match server version."
197
+ }));
198
+ }
199
+ }
200
+ class DataExportError extends import_GhostError.GhostError {
201
+ constructor(options = {}) {
202
+ super(mergeOptions(options, {
203
+ statusCode: 500,
204
+ errorType: "DataExportError",
205
+ message: "The server encountered an error whilst exporting data."
206
+ }));
207
+ }
208
+ }
209
+ class DataImportError extends import_GhostError.GhostError {
210
+ constructor(options = {}) {
211
+ super(mergeOptions(options, {
212
+ statusCode: 500,
213
+ errorType: "DataImportError",
214
+ message: "The server encountered an error whilst importing data."
215
+ }));
216
+ }
217
+ }
218
+ class EmailError extends import_GhostError.GhostError {
219
+ constructor(options = {}) {
220
+ super(mergeOptions(options, {
221
+ statusCode: 500,
222
+ errorType: "EmailError",
223
+ message: "The server encountered an error whilst sending email."
224
+ }));
225
+ }
226
+ }
227
+ class ThemeValidationError extends import_GhostError.GhostError {
228
+ constructor(options = {}) {
229
+ super(mergeOptions(options, {
230
+ statusCode: 422,
231
+ errorType: "ThemeValidationError",
232
+ message: "The theme has a validation error.",
233
+ errorDetails: {}
234
+ }));
235
+ }
236
+ }
237
+ class DisabledFeatureError extends import_GhostError.GhostError {
238
+ constructor(options = {}) {
239
+ super(mergeOptions(options, {
240
+ statusCode: 409,
241
+ errorType: "DisabledFeatureError",
242
+ message: "Unable to complete the request, this feature is disabled."
243
+ }));
244
+ }
245
+ }
246
+ class UpdateCollisionError extends import_GhostError.GhostError {
247
+ constructor(options = {}) {
248
+ super(mergeOptions(options, {
249
+ statusCode: 409,
250
+ errorType: "UpdateCollisionError",
251
+ message: "Unable to complete the request, there was a conflict."
252
+ }));
253
+ }
254
+ }
255
+ class HostLimitError extends import_GhostError.GhostError {
256
+ constructor(options = {}) {
257
+ super(mergeOptions(options, {
258
+ errorType: "HostLimitError",
259
+ hideStack: true,
260
+ statusCode: 403,
261
+ message: "Unable to complete the request, this resource is limited."
262
+ }));
263
+ }
264
+ }
265
+ class HelperWarning extends import_GhostError.GhostError {
266
+ constructor(options = {}) {
267
+ super(mergeOptions(options, {
268
+ errorType: "HelperWarning",
269
+ hideStack: true,
270
+ statusCode: 400,
271
+ message: "A theme helper has done something unexpected."
272
+ }));
273
+ }
274
+ }
275
+ class PasswordResetRequiredError extends import_GhostError.GhostError {
276
+ constructor(options = {}) {
277
+ super(mergeOptions(options, {
278
+ errorType: "PasswordResetRequiredError",
279
+ statusCode: 401,
280
+ message: "For security, you need to create a new password. An email has been sent to you with instructions!"
281
+ }));
282
+ }
283
+ }
284
+ class UnhandledJobError extends import_GhostError.GhostError {
285
+ constructor(options = {}) {
286
+ super(mergeOptions(options, {
287
+ errorType: "UnhandledJobError",
288
+ message: "Processed job threw an unhandled error",
289
+ level: "critical"
290
+ }));
291
+ }
292
+ }
293
+ class NoContentError extends import_GhostError.GhostError {
294
+ constructor(options = {}) {
295
+ super(mergeOptions(options, {
296
+ errorType: "NoContentError",
297
+ statusCode: 204,
298
+ hideStack: true
299
+ }));
300
+ }
301
+ }
302
+ class ConflictError extends import_GhostError.GhostError {
303
+ constructor(options = {}) {
304
+ super(mergeOptions(options, {
305
+ errorType: "ConflictError",
306
+ statusCode: 409,
307
+ message: "The server has encountered an conflict."
308
+ }));
309
+ }
310
+ }
311
+ class MigrationError extends import_GhostError.GhostError {
312
+ constructor(options = {}) {
313
+ super(mergeOptions(options, {
314
+ errorType: "MigrationError",
315
+ message: "An error has occurred applying a database migration.",
316
+ level: "critical"
317
+ }));
318
+ }
319
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ default: () => src_default,
33
+ utils: () => utils
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var ghostErrors = __toESM(require("./errors"));
37
+ var import_utils = require("./utils");
38
+ __reExport(src_exports, require("./errors"), module.exports);
39
+ var src_default = ghostErrors;
40
+ const utils = {
41
+ serialize: import_utils.serialize,
42
+ deserialize: import_utils.deserialize,
43
+ isGhostError: import_utils.isGhostError,
44
+ prepareStackForUser: import_utils.prepareStackForUser
45
+ };
package/cjs/utils.js ADDED
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var utils_exports = {};
30
+ __export(utils_exports, {
31
+ deserialize: () => deserialize,
32
+ isGhostError: () => isGhostError,
33
+ prepareStackForUser: () => prepareStackForUser,
34
+ serialize: () => serialize
35
+ });
36
+ module.exports = __toCommonJS(utils_exports);
37
+ var import_utils_copy = __toESM(require("@stdlib/utils-copy"));
38
+ var import_GhostError = require("./GhostError");
39
+ var errors = __toESM(require("./errors"));
40
+ const errorsWithBase = { ...errors, GhostError: import_GhostError.GhostError };
41
+ const _private = {
42
+ serialize(err) {
43
+ try {
44
+ return {
45
+ id: err.id,
46
+ status: err.statusCode,
47
+ code: err.code || err.errorType,
48
+ title: err.name,
49
+ detail: err.message,
50
+ meta: {
51
+ context: err.context,
52
+ help: err.help,
53
+ errorDetails: err.errorDetails,
54
+ level: err.level,
55
+ errorType: err.errorType
56
+ }
57
+ };
58
+ } catch (error) {
59
+ return {
60
+ detail: "Something went wrong."
61
+ };
62
+ }
63
+ },
64
+ deserialize(obj) {
65
+ return {
66
+ id: obj.id,
67
+ message: obj.detail || obj.error_description || obj.message,
68
+ statusCode: obj.status,
69
+ code: obj.code || obj.error,
70
+ level: obj.meta && obj.meta.level,
71
+ help: obj.meta && obj.meta.help,
72
+ context: obj.meta && obj.meta.context
73
+ };
74
+ },
75
+ /**
76
+ * @description Serialize error instance into oauth format.
77
+ *
78
+ * @see https://tools.ietf.org/html/rfc6749#page-45
79
+ *
80
+ * To not loose any error data when sending errors between internal services, we use the suggested OAuth properties and add ours as well.
81
+ */
82
+ OAuthSerialize(err) {
83
+ const matchTable = {
84
+ [errors.NoPermissionError.name]: "access_denied",
85
+ [errors.MaintenanceError.name]: "temporarily_unavailable",
86
+ [errors.BadRequestError.name]: "invalid_request",
87
+ [errors.ValidationError.name]: "invalid_request",
88
+ default: "server_error"
89
+ };
90
+ const { detail, code, ...properties } = _private.serialize(err);
91
+ return {
92
+ error: err.code || matchTable[err.name] || "server_error",
93
+ error_description: err.message,
94
+ ...properties
95
+ };
96
+ },
97
+ /**
98
+ * @description Deserialize oauth error format into GhostError instance.
99
+ * @constructor
100
+ */
101
+ OAuthDeserialize(errorFormat) {
102
+ try {
103
+ return new errorsWithBase[errorFormat.title || errorFormat.name || errors.InternalServerError.name](_private.deserialize(errorFormat));
104
+ } catch (err) {
105
+ return new errors.InternalServerError({
106
+ errorType: errorFormat.title || errorFormat.name,
107
+ ..._private.deserialize(errorFormat)
108
+ });
109
+ }
110
+ },
111
+ /**
112
+ * @description Serialize GhostError instance into jsonapi.org format.
113
+ * @param err
114
+ * @return {Object}
115
+ */
116
+ JSONAPISerialize(err) {
117
+ const errorFormat = {
118
+ errors: [_private.serialize(err)]
119
+ };
120
+ errorFormat.errors[0].source = {};
121
+ if (err.property) {
122
+ errorFormat.errors[0].source.pointer = "/data/attributes/" + err.property;
123
+ }
124
+ return errorFormat;
125
+ },
126
+ /**
127
+ * @description Deserialize JSON api format into GhostError instance.
128
+ */
129
+ JSONAPIDeserialize(errorFormat) {
130
+ errorFormat = errorFormat.errors && errorFormat.errors[0] || {};
131
+ let internalError;
132
+ try {
133
+ internalError = new errorsWithBase[errorFormat.title || errorFormat.name || errors.InternalServerError.name](_private.deserialize(errorFormat));
134
+ } catch (err) {
135
+ internalError = new errors.InternalServerError({
136
+ errorType: errorFormat.title || errorFormat.name,
137
+ ..._private.deserialize(errorFormat)
138
+ });
139
+ }
140
+ if (errorFormat.source && errorFormat.source.pointer) {
141
+ internalError.property = errorFormat.source.pointer.split("/")[3];
142
+ }
143
+ return internalError;
144
+ }
145
+ };
146
+ function serialize(err, options) {
147
+ options = options || { format: "jsonapi" };
148
+ let errorFormat = {};
149
+ try {
150
+ if (options.format === "jsonapi") {
151
+ errorFormat = _private.JSONAPISerialize(err);
152
+ } else {
153
+ errorFormat = _private.OAuthSerialize(err);
154
+ }
155
+ } catch (error) {
156
+ errorFormat.message = "Something went wrong.";
157
+ }
158
+ return errorFormat;
159
+ }
160
+ ;
161
+ function deserialize(errorFormat) {
162
+ let internalError = {};
163
+ if (errorFormat.errors) {
164
+ internalError = _private.JSONAPIDeserialize(errorFormat);
165
+ } else {
166
+ internalError = _private.OAuthDeserialize(errorFormat);
167
+ }
168
+ return internalError;
169
+ }
170
+ ;
171
+ function prepareStackForUser(error) {
172
+ const stackbits = error.stack?.split(/\n/) || [];
173
+ const hideStack = "hideStack" in error && error.hideStack;
174
+ if (hideStack) {
175
+ stackbits.splice(1, stackbits.length - 1);
176
+ } else {
177
+ stackbits.splice(1, 0, `Stack Trace:`);
178
+ }
179
+ if ("help" in error && error.help) {
180
+ stackbits.splice(1, 0, `${error.help}`);
181
+ }
182
+ if ("context" in error && error.context) {
183
+ stackbits.splice(1, 0, `${error.context}`);
184
+ }
185
+ const errorClone = (0, import_utils_copy.default)(error);
186
+ errorClone.stack = stackbits.join("\n");
187
+ return errorClone;
188
+ }
189
+ ;
190
+ function isGhostError(err) {
191
+ const errorName = import_GhostError.GhostError.name;
192
+ const legacyErrorName = "IgnitionError";
193
+ const recursiveIsGhostError = function recursiveIsGhostError2(obj) {
194
+ if (!obj || !obj.name) {
195
+ return false;
196
+ }
197
+ if (obj.name === errorName || obj.name === legacyErrorName) {
198
+ return true;
199
+ }
200
+ return recursiveIsGhostError2(Object.getPrototypeOf(obj));
201
+ };
202
+ return recursiveIsGhostError(err.constructor);
203
+ }
204
+ ;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var wrap_stack_exports = {};
20
+ __export(wrap_stack_exports, {
21
+ wrapStack: () => wrapStack
22
+ });
23
+ module.exports = __toCommonJS(wrap_stack_exports);
24
+ function wrapStack(err, internalErr) {
25
+ const extraLine = (err.stack?.split(/\n/g) || [])[1];
26
+ const [firstLine, ...rest] = internalErr.stack?.split(/\n/g) || [];
27
+ return [firstLine, extraLine, ...rest].join("\n");
28
+ }
29
+ ;