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

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