I am trying to make get calls using axios (activeURl and inactiveURl). If there is an error message from get call of activeURl then check data with inactiveURl. Throw error message only if both url doesn't yield any data. I should be getting data when making the nested call to inactiveURl but I am getting error messages all the time for inactiveURL.
axios({
url: activeURl,
method: "get",
})
.then(response => {
res.status(200).json(response.data);
})
.catch((err) => {
axios({
url: inactiveURl,
method: "get",
}).then(response => {
console.log('INside thEN');
res.status(200).json(response.data);
}).catch((err) => {
res.status(500).json({
message: err
});
})
Issue got resolved. The call to inactive url should be in the then instead of catch block as the "Not Found" message is, I believe, also considered a valid response.
axios({
url: activeURl,
method: "get",
})
.then(response => {
if(response.data !== "Not Found"){
res.status(200).json(response.data);
}else{
axios({
url: inactiveURl,
method: "get",
}).then(response => {
res.status(200).json(response.data);
})
}
})
.catch((err) => {
res.status(500).json({
message: err
});