Let's imagine I've got 2 awaits in a for loop, how can I make sure the first one is completed without throwing an error before executing the second await and thus looping again. I tried doing this using Puppeteer but it keeps looping even if the promise is not resolved...
for(var i = 0; i < 20; i++){
console.log('loop started')
await page1.goto('https://www.residentadvisor.net/dj.aspx?country=01').catch((err) =>{
console.log('Page load fail : '+ err)
if (err == 'Error: net::ERR_INTERNET_DISCONNECTED' || err == 'Error: net::ERR_NETWORK_CHANGED' || err == 'Error: net::ERR_NAME_NOT_RESOLVED'){
let refreshIntervalId = setInterval(() =>{
handleConnexionError(refreshIntervalId,page1)
}, 5000)
}
})
console.log('Page loaded : ' + i)
let teub = await page1.evaluate(() =>{
return document.querySelector('a').innerText
})
console.log('Evaluate done : ' + teub )
}
async function handleConnexionError(refreshIntervalId,page1){
console.log('Retrying to connect')
let errorHandle = true
await page1.goto('https://www.residentadvisor.net/dj.aspx?country=01').catch(() => {
errorHandle = false
})
if (errorHandle) {
console.log('Succesfully Reconnected')
clearInterval(refreshIntervalId)
return true
}
else {
console.log('Connection Fail Retrying in 10 sec ...')
}
}