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.
Constructor
AggregateError()- Creates a new
AggregateErrorobject.
Instance properties
AggregateError.prototype.message- Error message, defaults to
"". AggregateError.prototype.name- Error name, defaults to
AggregateError.
Examples
Catching an AggregateError
Promise.any([
Promise.reject(new Error("some error")),
]).catch(e => {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "All Promises rejected"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "some error" ]
});
Creating an AggregateError
try {
throw new AggregateError([
new Error("some error"),
], 'Hello');
} catch (e) {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "some error" ]
}
Specifications
| Specification |
|---|
| Promise.anyThe definition of 'AggregateError' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AggregateError
|
Chrome
Full support 85 |
Edge
No support No |
Firefox
Full support 79 |
IE
No support No |
Opera
No support No |
Safari
Full support 14 |
WebView Android
Full support 85 |
Chrome Android
Full support 85 |
Firefox Android
Full support 79 |
Opera Android
No support No |
Safari iOS
Full support 14 |
Samsung Internet Android
No support No |
nodejs
No support No |
AggregateError() constructor
|
Chrome
Full support 85 |
Edge
No support No |
Firefox
Full support 79 |
IE
No support No |
Opera
No support No |
Safari
Full support 14 |
WebView Android
Full support 85 |
Chrome Android
Full support 85 |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
Full support 14 |
Samsung Internet Android
No support No |
nodejs
No support No |
Legend
- Full support
- Full support
- No support
- No support
See also
AggregateError by Mozilla Contributors is licensed under CC-BY-SA 2.5.