4

I have a web page that includes images dynamically. if image is not present on the given path then I want to change the path of image. For checking that image is present on given path or not, I sent xhr request using following code.

var http = new XMLHttpRequest();
var url ='http://www.logodesignlove.com/images/negative/wwf-logo-design1.jpg'; //Image URL
http.open('GET',url, false);
http.send();
return http.status!=404;

If image is not present on path it returns 404 error and display it in console that "GET http://www.logodesignlove.com/images/negative/wwf-logo-design1.jpg 404 (Not Found)".

How can I prevent it from throwing in console? Is there a way to catch the error?

dang
  • 2,342
  • 5
  • 44
  • 91
  • 404 isn't an error - it's a response status. The only place you can change it is the place that sends it - the server. Do you have access to the server that holds the images? – Reinstate Monica Cellio Jan 31 '17 at 08:29
  • Also, why does it matter? 99% of visitors don't even know the console exists, and it's doing exactly what it should do in this case. If you mask things like 404 errors then you yourself will miss them when they may need to be fixed. – Reinstate Monica Cellio Jan 31 '17 at 08:41
  • 1
    Well, I'd say it matters - see, I found this because I run into the same issue. There are a lot of message in the console that I'd like to remove to be able to see "my" important output. I know that some resources can give a 404 error, but my code handles this very well anyway. So nobody should be bothered with this output. Seem I'll go with what was recommended somewhere else: drop using HEAD requests and install a service on the server that I can query using POST requests whether a file exists. – Axel Heider Oct 23 '17 at 10:07

2 Answers2

0
  1. copy this string

    ^((?!404 \(Not Found\)).)*$
    
  2. open filter in console as on this image this image

  3. past string in filter as on this image this image
Andrey Kudriavtsev
  • 1,124
  • 11
  • 19
0

If you don't want to see error messages;

  1. Open Console
  2. Type -404 in the filter field
Project Mayhem
  • 439
  • 5
  • 12