@trenskow/api-error 2.3.1 → 2.3.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/index.js +9 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -254,25 +254,27 @@ class Aggregated extends ApiError {
|
|
|
254
254
|
|
|
255
255
|
this._errors = options.errors || [];
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this._errors = this._errors.map((error) => this._check(error));
|
|
257
|
+
this._errors = this._check(this._errors);
|
|
260
258
|
|
|
261
259
|
}
|
|
262
260
|
|
|
263
|
-
_check(
|
|
264
|
-
if (error instanceof ApiError) return
|
|
265
|
-
throw new TypeError('Error must
|
|
261
|
+
_check(errors) {
|
|
262
|
+
if (Array.isArray(errors) && errors.every((error) => error instanceof ApiError)) return errors;
|
|
263
|
+
throw new TypeError('Error must an array of type `ApiError`.');
|
|
266
264
|
}
|
|
267
265
|
|
|
268
266
|
add(error) {
|
|
269
|
-
this._errors.
|
|
267
|
+
this._errors = this._errors.concat(this._check(error));
|
|
270
268
|
}
|
|
271
269
|
|
|
272
270
|
get errors() {
|
|
273
271
|
return this._errors;
|
|
274
272
|
}
|
|
275
273
|
|
|
274
|
+
set errors(errors) {
|
|
275
|
+
this._errors = this._check(errors);
|
|
276
|
+
}
|
|
277
|
+
|
|
276
278
|
toJSON(options = {}) {
|
|
277
279
|
return merge(super.toJSON(options), {
|
|
278
280
|
errors: this._errors.map((error) => error.toJSON(options))
|