Angular and Raygun
Christian
Posted on
May 15 2014
What is the best(easiest) way to get client javascript errors when using angular.js?
Callum
Posted on
May 16 2014
Here's one approach that works:
In your index.html file reference Raygun4JS and initialize it:
<script src="js/raygun.min.js" type="text/javascript"></script>
<script>Raygun.init('your_api_key').attach();</script>
Attach is optional, and will pick up JS Errors thrown outside of your angular controllers etc.
Then in your main app.js with your module definition, add an exception handler onto your module:
var app = angular.module('myapp', ['ngRoute']);
app.factory('$exceptionHandler', function () {
return function (exception) {
Raygun.send(exception);
}
});
You might also like to add console logging in there as this overrides the default $exceptionHandler function.
Hope this works well for you, let us know if you need further assistance.