So just like the title says im trying to create a javascript loop that calls an API, if there is data returned it sets the let variable and jumps out the loop but if it errors it retries 3 times. I did some googling and came up with the following but its not working and i cant understand why?
let data
const maxTries = 3
for (let i = 0; i <= maxTries; i++) {
try {
data = await getJson(url, true)
if (data) {
return data
}
} catch (err) {
console.error(err)
throw err
}
}