4

我已经设置了一个 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>

感谢您的反馈意见

4

3 回答 3

3

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

$( document ).ajaxError(function( event, request, settings ) {
  Raven.captureException(new Error(JSON.stringify(request)));
});
于 2016-03-01T12:23:39.220 回答
2

关于函数包装的Sentry文档将是这方面最规范的来源,但有效地告诉你按照 Bob 所说的去做。:)

于 2016-03-02T03:52:21.727 回答
1

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

$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
  var new_obj= Object.assign({},jqXHR, ajaxSettings);
  Raven.captureMessage(thrownError || jqXHR.statusText, {
        extra: new_obj
  });
});
于 2017-05-03T20:41:17.357 回答