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

272
Visualizações
differentiating net::ERR_NAME_NOT_RESOLVED from net::ERR_CONNECTION_REFUSED

I have a webpage that attempts to set the src of an image. I fully expect errors depending on what image I ask for, and I want to catch the error messages and have different responses depending on which error I get.

I am looking to compare net::ERR_CONNECTION_REFUSED vs net::ERR_NAME_NOT_RESOLVED.

I tried looking at the error event, but there doesn't appear to be any information about the actual error message or type in the event.

both events look like this

Event {isTrusted: true, type: 'error', target: img, currentTarget: img, eventPhase: 2, …}
isTrusted: true
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: null
defaultPrevented: false
eventPhase: 0
path: (5) [img, body, html, document, Window]
returnValue: true
srcElement: img
target: img
timeStamp: 2342.2000000178814
type: "error"

I would do a try/catch as that seems to return the error message as a string, but I'm not sure how to actually catch it, as the error is on the HTTP request, not the src change.

update I tried accessing the path with an XMLHttpRequest, and catching the send, but I don't get the error message in the try/catch statement doing that. The debugger shows the error is at h.send() but the catch statement is not executed.

example

try{
    h=new XMLHttpRequest();
    h.open("GET","https://address");
    h.send();
}catch (e){
    console.log("error");
    console.log("ERROR:",e);
}
about 4 years ago · Juan Pablo Isaza
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