Martyn Ball
Martyn Ball

Reputation: 4885

Handle 404 Error without dumping the default error in log.

i'm detecting if an image exists and then handling the response differently, however as soon as I send the HTTP Request and the image doesn't exist I still get the default 404 error come up in the console. As follows:

enter image description here

I'm checking for 2 images, one exists and the other doesn't as you can see by the true and false, how can I stop the one above?

I tried catching the error and simply displaying nothing, but it still appears.

Code:

var http = new XMLHttpRequest();
http.open('HEAD', this, false);
http.send();
return http.status !== 404;

Upvotes: 1

Views: 129

Answers (2)

Carson
Carson

Reputation: 152

you can rewrite 404 and check parameters to a default image, and XHR throws default image. you can rewrite in your rules.

edited1 The only server-side can rewrite URL.

Upvotes: 0

Quentin
Quentin

Reputation: 943518

There is no way to programmatically suppress the "XHR resulted in a 404 Error" message in the Developer Tools console.

Upvotes: 3

Related Questions