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

374
Vistas
Fetch call results in net::ERR_CONNECTION_REFUSED, how to fetch a another server when error arises

I am developing an app in javascript that requires me to make fetch calls to a secondary server when the primary is down. I have shutdown the primary in order to have the app fetch the secondary server. The fetch call for my first effort looks something like this.

try {
    fetch(`https://server1`)
        .then(response => {
            if (!response.ok) {
                fetch(`https://server2`)
                    .then(response => {
                        return response.text();
                    })
            }
            return response.text();
        })
} catch (err) {

}

As shutting down the server results in net::ERR_CONNECTION_REFUSED I have nothing happens in the catch error. I have also tried adding a flag variable and having it run through fetching the first server then the second as a result of the flag value:

var flag = false;

try {
    fetch(`https://server1`)
        .then(response => {
            if (response.ok) {
                flag = true;

            }

            return response.text();
        })
        .catch((err) => {
            flag = true;
        });

    if (!flag) {
        fetch(`https://server2`)
        .then(response => {
            if (response.ok) {
                flag = false;

            }
            return response.text();
        });
        
    }

}

Any tips appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
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