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

213
Views
try catch, not catching fetch() 502 gateway exception

For some reason, whenever there is an invalid URL that causes a 502 exception, the code throws an error in the console and breaks. Ignoring the try {} catch{}

  async function getHeight(url) {
    const serviceUrl = url
    try {
      const request = fetch(Proxy+"http://"+url+"/v1/query/height", {
        method: "post",
        headers: {
          "Content-Type": "application/json"
        },
      });

      return [serviceUrl, request]
    }
    catch {
      return [serviceUrl, "failed"]
    }
  }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Ran into this before and it appears the browser errors it out. But you should be able to catch it. Try it this way.

try {

} catch(error) {
  if (!error.response){
    return [serviceUrl, "No server response."]
  } else if (error.response.status === 502) {
    return [serviceUrl, "Bad gateway"]
  } else { [serviceUrl, "Server unable to process request."] }
}
about 4 years ago · Santiago Trujillo 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!