@trenskow/api-error 2.4.8 → 2.4.10

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.
Files changed (2) hide show
  1. package/index.js +13 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -288,19 +288,27 @@ class Aggregated extends ApiError {
288
288
  statusCode: 400
289
289
  }));
290
290
 
291
- this._errors = options.errors || options.underlying?.errors || [];
292
-
293
- this._errors = this._check(this._errors);
291
+ this._errors = options.underlying?.errors || options.errors || [];
294
292
 
295
293
  }
296
294
 
297
295
  _check(errors) {
298
- if (Array.isArray(errors) && errors.every((error) => error instanceof ApiError)) return errors;
296
+
297
+ if (Array.isArray(errors) && errors.every((error) => {
298
+ let prototype = Object.getPrototypeOf(error);
299
+ while (prototype !== null) {
300
+ if (prototype.constructor.name === 'ApiError') return true;
301
+ prototype = Object.getPrototypeOf(prototype);
302
+ }
303
+ return false;
304
+ })) return errors;
305
+
299
306
  throw new TypeError('Error must an array of type `ApiError`.');
307
+
300
308
  }
301
309
 
302
310
  add(error) {
303
- this._errors = this._errors.concat(this._check(error));
311
+ this._errors = this._errors.concat(this._check(Array.isArray(error) ? error : [error]));
304
312
  }
305
313
 
306
314
  get errors() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/api-error",
3
- "version": "2.4.8",
3
+ "version": "2.4.10",
4
4
  "description": "A small collection of error objects that can be used for REST APIs.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,6 +26,6 @@
26
26
  "merge": "^2.1.1"
27
27
  },
28
28
  "devDependencies": {
29
- "eslint": "^8.57.0"
29
+ "eslint": "^9.9.0"
30
30
  }
31
31
  }