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

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

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 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