最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use Sentry's Raven JS to collect all HTTP errors - Stack Overflow

programmeradmin2浏览0评论

I have setup a Sentry application to collect HTTP / JS errors that can occur on the client side. However, it seems that when I try to make some 400 HTTP requests, Sentry failed to capture the request accordingly.

Is it the default behavior of Sentry, or if something missing in my code (below)?

<!DOCTYPE html>
<html>
    <head>
            <title>Hi there</title>
            <script src="//code.jquery/jquery-1.12.0.min.js"></script>
            <script src=".1.1/raven.min.js"></script>
            <script>Raven.config('http://[email protected]/4').install();</script>
    </head>
    <body>
        Hello the world :-)
        <script type="text/javascript">
            $.get("/");
        </script>
    </body>
</html>

Thanks for your feedback

I have setup a Sentry application to collect HTTP / JS errors that can occur on the client side. However, it seems that when I try to make some 400 HTTP requests, Sentry failed to capture the request accordingly.

Is it the default behavior of Sentry, or if something missing in my code (below)?

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

Thanks for your feedback

Share Improve this question asked Mar 1, 2016 at 12:18 Hoang HUAHoang HUA 3354 silver badges7 bronze badges 1
  • please check this link: stackoverflow./questions/49462553/… – Rajashekhar Commented Apr 1, 2018 at 9:17
Add a ment  | 

3 Answers 3

Reset to default 3

You can use ajaxError handler ( https://api.jquery./ajaxError/ ):

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

Sentry docs on function wrapping will be the most canonical source on this, but effectively tell you to do what Bob says. :)

I found this to work best bining all available information into additional data field:

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

评论列表(0)

  1. 暂无评论