The AggregateError
object represents an error when several errors need to be wrapped in a single error. It is thrown when multiple errors need to be reported by an operation, for example by Promise.any()
, when all promises passed to it reject.
AggregateError
is a subclass of Error
.
Instance properties
Also inherits instance properties from its parent Error
.
These properties are defined on AggregateError.prototype
and shared by all AggregateError
instances.
-
AggregateError.prototype.constructor
-
The constructor function that created the instance object. For AggregateError
instances, the initial value is the AggregateError
constructor.
-
AggregateError.prototype.name
-
Represents the name for the type of error. For AggregateError.prototype.name
, the initial value is "AggregateError"
.
These properties are own properties of each AggregateError
instance.
-
errors
-
An array representing the errors that were aggregated.
Instance methods
Inherits instance methods from its parent Error
.
Catching an AggregateError
Promise.any([Promise.reject(new Error("some error"))]).catch((e) => {
console.log(e instanceof AggregateError);
console.log(e.message);
console.log(e.name);
console.log(e.errors);
});
Creating an AggregateError
try {
throw new AggregateError([new Error("some error")], "Hello");
} catch (e) {
console.log(e instanceof AggregateError);
console.log(e.message);
console.log(e.name);
console.log(e.errors);
}
Specifications
Browser compatibility
|
Desktop |
Mobile |
Server |
|
Chrome |
Edge |
Firefox |
Opera |
Safari |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
WebView Android |
Deno |
Node.js |
AggregateError |
85 |
85 |
79 |
71 |
14 |
85 |
79 |
60 |
14 |
14.0 |
85 |
1.2 |
15.0.0 |
AggregateError |
85 |
85 |
79 |
71 |
14 |
85 |
79 |
60 |
14 |
14.0 |
85 |
1.2 |
15.0.0 |
errors |
85 |
85 |
79 |
71 |
14 |
85 |
79 |
60 |
14 |
14.0 |
85 |
1.2 |
15.0.0 |
serializable_object |
No |
No |
103Serialized properties: name , message , cause , errors .
|
No |
No |
No |
103Serialized properties: name , message , cause , errors .
|
No |
No |
No |
No |
No |
No |