Given:
const img = document.getElementById('img-id');
img.onerror = function() { … };
img.src = new_url;
Changing the source of the image element may result in my very specific use case in either:
- A server status response
400 Bad Request
, or - A server status response
200 OK
with aContent-Type
HTTP header that is not an image.
I would like to differentiate between both in the .onerror
function.
I see the difference in the F12 console error of Chrome/Blink-based browsers and would like to capture this in a pure JavaScript conditional. Has the event related to .onerror
any properties that may help to achieve this?
Note: This is for use in a progressive web application. By consequence, a solution that works with Chrome and Safari would suffice.