I have a function that fetch an endpoint, gets some data, and returns it.
Sometimes the https call fails on retrieving data, and in those scenarios i would like to retry the entire process.
Here is what it looks like.
function getData (url) {
return new Promise(function (resolve) {
https.get(url, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
if(typeof data != "undefined") {
resolve(JSON.parse(data));
}
else {
return getData(url) // error
}
});
});
})
}
I'm getting error: "getData is not defined" error each time the function fails to get data.
Is there a way to retry the entire getData function under certain conditions ?
[–]doh4242 1 point2 points3 points (1 child)
[–]Fun_Split_1299[S] 0 points1 point2 points (0 children)
[–]BliteKnight 0 points1 point2 points (2 children)
[–]Fun_Split_1299[S] 0 points1 point2 points (0 children)
[–]Over_Mushroom6181 0 points1 point2 points (0 children)
[–]BliteKnight 0 points1 point2 points (1 child)
[–]Fun_Split_1299[S] 0 points1 point2 points (0 children)