Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda