Promise.any([]).catch((error) => {
console.error(error); // AggregateError: No Promise in Promise.any was resolved
});AggregateError: No Promise in Promise.any was resolved
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const promises = [
fetch("/data-location1"),
fetch("/data-location1"),
fetch("/data-location1"),
];
Promise.any(promises)
.then((value) => console.log(value))
.catch((error) => {
// None of the fetches were successful
for (const e of error.errors) {
console.error(e);
}
});
// Using await
async function fetchFirstSuccessful() {
try {
const value = await Promise.any(promises);
console.log(value);
} catch (error) {
for (const e of error.errors) {
console.error(e);
}
}
}