AggregateError

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.

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.

Compared to SuppressedError, AggregateError represents a list of unrelated errors, while SuppressedError represents an error that happened during the handling of another error.

AggregateError is a subclass of Error.

Constructor

AggregateError()

Creates a new AggregateError object.

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.

Examples

Catching an AggregateError

js
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

js
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
ECMAScript® 2027 Language Specification
# sec-aggregate-error-objects

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
AggregateError
Chrome – Full support
Chrome 85 (Release date: 2020-08-25)
footnote Full support
Edge – Full support
Edge 85 (Release date: 2020-08-27)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 71 (Release date: 2020-09-15)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 85 (Release date: 2020-08-25)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 85 (Release date: 2020-08-25)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.2 (Release date: 2020-07-13)
footnote Full support
Node.js – Full support
Node.js 15 (Release date: 2020-10-20)
footnote Full support
AggregateError() constructor
Chrome – Full support
Chrome 85 (Release date: 2020-08-25)
footnote Full support
Edge – Full support
Edge 85 (Release date: 2020-08-27)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 71 (Release date: 2020-09-15)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 85 (Release date: 2020-08-25)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 85 (Release date: 2020-08-25)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.2 (Release date: 2020-07-13)
footnote Full support
Node.js – Full support
Node.js 15 (Release date: 2020-10-20)
footnote Full support
errors
Chrome – Full support
Chrome 85 (Release date: 2020-08-25)
footnote Full support
Edge – Full support
Edge 85 (Release date: 2020-08-27)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 71 (Release date: 2020-09-15)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 85 (Release date: 2020-08-25)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 85 (Release date: 2020-08-25)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.2 (Release date: 2020-07-13)
footnote Full support
Node.js – Full support
Node.js 15 (Release date: 2020-10-20)
footnote Full support
AggregateError is serializable
Chrome – Full support
Chrome 98 (Release date: 2022-02-01)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
Edge – Full support
Edge 98 (Release date: 2022-02-03)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
Firefox – Full support
Firefox 103 (Release date: 2022-07-26)
footnote
footnote AggregateError serializes to the AggregateError type, with properties name, message, cause, and errors.
Opera – Full support
Opera 84 (Release date: 2022-02-16)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
Safari – Full support
Safari 17 (Release date: 2023-09-18)
footnote Full support
Chrome Android – Full support
Chrome Android 98 (Release date: 2022-02-01)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
Firefox for Android – Full support
Firefox for Android 103 (Release date: 2022-07-26)
footnote
footnote AggregateError serializes to the AggregateError type, with properties name, message, cause, and errors.
Opera Android – Full support
Opera Android 68 (Release date: 2022-03-30)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
Safari on iOS – Full support
Safari on iOS 17 (Release date: 2023-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 18 (Release date: 2022-08-08)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
WebView Android – Full support
WebView Android 98 (Release date: 2022-02-01)
footnote
footnote AggregateError serializes to the Error type, without additional properties.
WebView on iOS – Full support
WebView on iOS 17 (Release date: 2023-09-18)
footnote Full support
Bun – No support
Bun
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also