W3cubDocs

/JavaScript

AggregateError

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 AggregateError object.

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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
AggregateError 85 No 79 No No 14
AggregateError() constructor 85 No 79 No No 14
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
AggregateError 85 85 79 No 14 No
AggregateError() constructor 85 85 No No 14 No
Server
Node.js
AggregateError No
AggregateError() constructor No

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError