so what i want to do is to keep trying to get the data check if the value that i want does exist if it doesn't exist it would return an error and then re do the action until the value does exist. so what i have till now this is the https call
test = async() => {
console.log("Hellow")
now = new Date();
const https = require("https");
https.get("website",{ agent: proxyy },
(res) => {
var body = "";
res.on("data", function (chunk) {
body += chunk;
});
res.on("end", function () {
var resp = JSON.parse(body);
data_wanted = resp.data
const desiredItem = data_wanted.find((item) =>
item.name.includes("data")
);
console.log(desiredItem)
});
}
);
};
what i did but didn't worked out
while (flag = true ){
let flag = false
try{
await test()// test is the same function above
}catch(e){
flag = true
}
}
so the try catch dont catch any error so the flag wont change to true , and neither the while loop work alone for some reason
EDIT1 so what i think is happening since https is async the try/catch is running before the https call is finished.