JavaScript AggregateError Object
An AggregateError wraps several errors in one. It is thrown by Promise.any() when every promise rejects, with the individual errors in its errors property.
Description
An AggregateError represents several errors at once. Its errors property is an array of the individual errors. JavaScript throws one from Promise.any() when all of the promises passed to it reject, since there is no single reason to report. You can create your own to report several validation problems together.
You can create your own with new AggregateError(errors, message), which is handy when validating a form or a batch of items and you want to report every problem at once rather than stopping at the first. The errors property holds whatever you passed in, normally an array of Error objects, and the usual message and name properties describe the group as a whole.
AggregateError is a subclass of Error, so err instanceof Error is true, and the optional cause option works as it does for other errors. When logging, loop over errors to show each individual message, since most consoles only show the top-level message by default.
Creating
new AggregateError(errors, message)Example
Browser Support
The following information will show you the current browser support for the AggregateError object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





