0

I have this code:

var url2 = 'https://vechainstats.com/nft/vereapers/2576/';
var img = document.createElement('img');
img.src = url2;

The link doesn't exist. So, I get in the console:

Console

GET https://vechainstats.com/nft/vereapers/2576/ 404

How can I get this error message (404) in JavaScript?

Thank you


I've tried adding addEventListener('error') to img but the log doesn't show 404 error. I've tried try / catch. I've tried fetch (CORS & CORB problems).

11
  • 2
    Img error event? Using addEventListener Commented Sep 9, 2022 at 13:04
  • Why do you need the 404 specifically? Why is knowing that there has been an error not enough? Looks a bit like an XY Problem. Commented Sep 9, 2022 at 13:06
  • Does this help? using onerror for 404 for src different then img Commented Sep 9, 2022 at 13:09
  • Does this answer your question? How can I catch a 404 error in Javascript? Commented Sep 9, 2022 at 13:12
  • @JaromandaX I've tried this but doesn't return the state... Commented Sep 9, 2022 at 13:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.