@trenskow/api-error 2.5.40 → 2.5.42
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/index.js +7 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -22,15 +22,16 @@ class ApiError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
static parse(data, statusCode, origin) {
|
|
25
|
+
static parse(data, statusCode, origin, stack) {
|
|
26
26
|
|
|
27
27
|
let options = merge({}, data, {
|
|
28
28
|
message: data.message,
|
|
29
29
|
statusCode: statusCode,
|
|
30
|
-
origin: origin
|
|
30
|
+
origin: origin,
|
|
31
|
+
stack: stack
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
options.errors = options.errors?.map((error) => ApiError.parse(error, statusCode, origin));
|
|
34
|
+
options.errors = options.errors?.map((error) => ApiError.parse(error, statusCode, origin, error.stack));
|
|
34
35
|
|
|
35
36
|
return new (this._type(data.name || 'bad-request'))(options);
|
|
36
37
|
|
|
@@ -64,11 +65,13 @@ class ApiError extends Error {
|
|
|
64
65
|
this._name = options.name;
|
|
65
66
|
this._entity = options.entity;
|
|
66
67
|
this._statusCode = options.statusCode || 500;
|
|
68
|
+
this._stacked = options.stack;
|
|
67
69
|
|
|
68
70
|
delete options.message;
|
|
69
71
|
delete options.name;
|
|
70
72
|
delete options.entity;
|
|
71
73
|
delete options.statusCode;
|
|
74
|
+
delete options.stack;
|
|
72
75
|
|
|
73
76
|
this._options = options;
|
|
74
77
|
|
|
@@ -115,6 +118,7 @@ class ApiError extends Error {
|
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
get stacked() {
|
|
121
|
+
if (this.actual._stacked) return this.actual._stacked;
|
|
118
122
|
return ApiError.stackToJSON(this.actual.stack);
|
|
119
123
|
}
|
|
120
124
|
|