How do I alert() a 503 HTTP status code for failure to load an image

Is there a way to alert() a 503 HTTP status code for failure to load an image? if my site fails to load an image and a 503 error appears in the console as usual, I want to be able to alert() it.