Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda