I have a multiple async functions which all send a request to a server, and if there's a error they catch it then retry the function, these functions rely on the data from the previous function, so they have to send one after the other, the problem is whenever I call these functions and there's a error, it keeps retrying it like I want, but it goes on to the next function after, instead of waiting waiting for the previous one to return the resolved response.
const request1 = async () => {
try {
const data = await rp.get(link, options)
return data
} catch (err) {
request1()
}
}
const request2 = async (data) => {
try {
const data = await rp.get(link, options)
return data
} catch (err) {
request2()
}
}
const getData = async() => {
await request1()
await request2()
})
getData()
whenever I call the getData() function, it awaits the first request, but even if it has an error, it moves on the second request right after, instead of waiting for the first request to resolve, also I need a try catch for all the request i send instead of one, because if there is a error i just want to retry that one step, not the full thing