简体   繁体   English

如何从DOM错误事件中获取详细消息

[英]How do I get detailed message from a DOM error event

I'm trying to understand Chrome's implementation of html import such as 我正在尝试了解Chrome对html导入的实现,例如

 <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 . 但是,错误事件并没有真正传达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. 我想知道是否有任何方法可以使我从错误事件中获得更多收益,例如失败原因和HTTP状态代码。

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. 如果触发了错误事件处理程序,则可以使用XMLHttpRequestfetch 重播请求,以获取有关失败的更多信息。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM