Using Sentry/Raven.js with AngularJS to catch exceptions
AngularJS makes it easy to override their default exception handler. This means we can plug in Raven-js to send all client exceptions to Sentry :)
Just create your own module and service with the same name as the default AngularJS provider ($exceptionHandler):
angular.module('myExceptions', []).factory('$exceptionHandler',
['$window', '$log',
function ($window, $log) {
if ($window.Raven) {
console.log('Using the RavenJS exception handler.');
Raven.config('YOUR_PUBLIC_DSN').install();
return function (exception, cause) {
$log.error.apply($log, arguments);
Raven.captureException(exception);
};
} else {
console.log('Using the default logging exception handler.');
return function (exception, cause) {
$log.error.apply($log, arguments);
};
}
}
]);
Just get your proper Sentry public DSN and add your allowed domains in the Sentry security settings for your app.