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.
* Some parts of this feature may have varying levels of support.
El objeto AggregateError
representa un error cuando se deben agrupar varios errores en un solo error. Se lanza cuando una operación necesita informar de varios errores, por ejemplo, Promise.any()
, cuando todas las promesas que se le pasan son rechazadas.
Constructor
AggregateError()
-
Crea un nuevo objeto
AggregateError
.
Propiedades de la instancia
AggregateError.prototype.message
-
Mensaje de error, el valor predeterminado es
""
(la cadena vacía). AggregateError.prototype.name
-
Nombre del error, el valor predeterminado es
AggregateError
.
Ejemplos
Capturar un error agregado
Promise.any([Promise.reject(new Error("algún error"))]).catch((e) => {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "Todas las promesas rechazadas"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "algún error" ]
});
Crear un AggregateError
try {
throw new AggregateError([new Error("algún error")], "Hola");
} catch (e) {
console.log(e instanceof AggregateError); // true
console.log(e.message); // "Hola"
console.log(e.name); // "AggregateError"
console.log(e.errors); // [ Error: "algún error" ]
}
Especificaciones
Specification |
---|
ECMAScript® 2025 Language Specification # sec-aggregate-error-objects |
Compatibilidad con navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AggregateError | ||||||||||||||
AggregateError() constructor | ||||||||||||||
errors | ||||||||||||||
AggregateError is serializable |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.