How do I get detailed message from a DOM error event

1k views Asked by At

I'm trying to understand Chrome's implementation of html import such as

 <link id="test_component" rel="import" href="http://localhost:8888/fail.html" onerror="handler(event)">

However the error event doesn't really convey much useful message as specified in MDN . I wonder if there's any way I can get more out of the error event such as reason of failure and HTTP status code.

1

There are 1 answers

1
Supersharp On BEST ANSWER

If the error event handler is triggered, you can replay the request by using XMLHttpRequest or fetch in order to get more information about the failure.

function handler(event) 
{
    fetch(event.target.href)
        .then( resp => console.info(resp.status) )
        .catch( err => console.log(err) )
}