Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Multiple condition based http calls using axios in Node

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
            });
        })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
            });
 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!