繁体   English   中英

使用Sentry的Raven JS收集所有HTTP错误

[英]Use Sentry's Raven JS to collect all HTTP errors

我已经设置了一个Sentry应用程序来收集客户端可能发生的HTTP / JS错误。 但是,似乎当我尝试发出大约400个HTTP请求时,Sentry无法相应地捕获请求。

它是Sentry的默认行为,还是我的代码中缺少的东西(如下)?

<!DOCTYPE html>
<html>
    <head>
            <title>Hi there</title>
            <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
            <script src="https://cdn.ravenjs.com/2.1.1/raven.min.js"></script>
            <script>Raven.config('http://xxx@xxx.xxxxx.com/4').install();</script>
    </head>
    <body>
        Hello the world :-)
        <script type="text/javascript">
            $.get("http://somehttp400url.com/");
        </script>
    </body>
</html>

感谢您的反馈意见

您可以使用ajaxError处理程序( https://api.jquery.com/ajaxError/ ):

$( document ).ajaxError(function( event, request, settings ) {
  Raven.captureException(new Error(JSON.stringify(request)));
});

关于功能包装的 Sentry 文档将是这方面最规范的来源,但有效地告诉你做鲍勃所说的。 :)

我发现这可以最好地将所有可用信息组合到其他数据字段中:

$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
  var new_obj= Object.assign({},jqXHR, ajaxSettings);
  Raven.captureMessage(thrownError || jqXHR.statusText, {
        extra: new_obj
  });
});

暂无
暂无

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

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