In this case I'd want to log the error, or display a notice that the chapter couldn't be loaded. For this we need to catch the rejections and turn them into values we can iterate over with for await/of.
Promise.allSettled() does this for us, but forces us to wait until all promises are... settled. A streaming version would give back an async iterable to we could handle promises in order as soon as they're ready. Or we can just convert into the same return type as allSettled() ourselves:
async function showChapters(chapterURLs) {
const chapterPromises = chapterURLs.map(async (url) => {
try {
const response = await fetch(url);
return {status: "fulfilled", value: await response.json()};
} catch (e) {
return {status: "rejected", reason: e};
}
});
for await (const chapterData of chapterPromises) {
// Make sure this function renders or logs something for rejections
appendChapter(chapterData);
}
}