Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda