Search code examples
javascriptloggingsentryraven

Use Sentry's Raven JS to collect all HTTP errors


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.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://[email protected]/4').install();</script>
    </head>
    <body>
        Hello the world :-)
        <script type="text/javascript">
            $.get("http://somehttp400url.com/");
        </script>
    </body>
</html>

Thanks for your feedback


Solution

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

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