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

375
Views
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
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!