First, let's everybody look at this adorable owl:
http://happy.fm/wp-content/uploads/2011/10/random-owl.jpg
I'm using that as a test image to see if I can detect, using client-side Javascript, whether a given URL is a legit image. I hunted around online and found some simple code that's supposed to work:
const img = new Image();
img.onload = () => {
console.log("HOORAY! SUCCESS!", img);
}
img.onerror = () => {
console.log("BOO! FAIL!")
}
img.src = values.image;
If I put in a URL which has a valid domain, but bad file path, like this:
http://happy.fm/wp-content/uploads/2011/10/random-owlDOESNOTEXIST.jpg
...then onerror()
fires reliably. However, if the domain is bogus, like this:
http://happy.fmDOESNOTEXIST/wp-content/uploads/2011/10/random-owl.jpg
...then onerror()
never fires. Is this, like, expected behavior? Is there any way around this?
And yes, I realize doing only client-side validation isn't the best way to really handle this issue, but pretend for the moment that this is the only way.
EDIT: it's worth mentioning that I'm seeing this error in a Node.js/Webpack local environment, running on top of the webpack-dev-server. Maybe this becomes some sort of permissions problem.