miushock
miushock

Reputation: 1097

How do I get detailed message from a DOM error event

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.

Upvotes: 3

Views: 1194

Answers (1)

Supersharp
Supersharp

Reputation: 31219

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) )
}

Upvotes: 1

Related Questions