@trenskow/api-error 2.3.1 → 2.3.3

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 +9 -7
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -254,25 +254,27 @@ class Aggregated extends ApiError {
254
254
 
255
255
  this._errors = options.errors || [];
256
256
 
257
- if (!Array.isArray(this._errors)) this._errors = [this._errors];
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(error) {
264
- if (error instanceof ApiError) return error;
265
- throw new TypeError('Error must be of type `ApiError`.');
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.push(this._check(error));
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))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/api-error",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "A small collection of error objects that can be used for REST APIs.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,10 +22,10 @@
22
22
  },
23
23
  "homepage": "https://github.com/trenskow/api-error#readme",
24
24
  "dependencies": {
25
- "@trenskow/stack": "^0.1.3",
25
+ "@trenskow/stack": "^0.1.7",
26
26
  "merge": "^2.1.1"
27
27
  },
28
28
  "devDependencies": {
29
- "eslint": "^8.13.0"
29
+ "eslint": "^8.35.0"
30
30
  }
31
31
  }