I have an array of promises that looks like this:
const content = await getData() //gets data from API
const drinkURL = content.drinks.map( item => "lookup.php?i=" + item.idDrink) // gets element in the API end-point
const getInfo = async() => {
let allPromises = Promise.all(drinkURL.map(item => getData(item)))
allPromises.catch(e => console.log(e)) // Trying to catch any errors here, but can't.
return allPromises
}
I want to add a catch statement in case any of the promises can not resolve.
I have tried writing it inside the getInfo function, and after the .then() inside the next snippet.
const view = `
<div class="Drink-card">
<a href="/">Home</a>
${await getInfo()
.then(ele => ele.map(item => item.drinks.map( drink => `
<article class="Drink-main">
<img src="${drink.strDrinkThumb}" alt="${drink.strDrink}">
<h2>${drink.strDrink}</h2>
</article>
`)).join("")).catch(e => console.log(e))//Does not work in here either}
I have tried a bunch of ways but can't come up with a working result.
Thanks!
