Created
May 21, 2014 15:13
-
-
Save mukgupta/4fb772eec686bf8b716f to your computer and use it in GitHub Desktop.
Raven-js Angularjs plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Angular.js plugin | |
* | |
* Provides an $exceptionHandler for Angular.js | |
*/ | |
;(function(Raven, angular) { | |
'use strict'; | |
// quit if angular isn't on the page | |
if (!angular) { | |
return; | |
} | |
function ngRavenProvider($provide) { | |
$provide.decorator('$exceptionHandler', [ | |
'RavenConfig', '$delegate', | |
ngRavenExceptionHandler | |
]); | |
} | |
function ngRavenExceptionHandler(RavenConfig, $delegate) { | |
if (!RavenConfig) | |
throw new Error('RavenConfig must be set before using this'); | |
Raven.config(RavenConfig.dsn, RavenConfig.config); | |
return function angularExceptionHandler(ex, cause) { | |
$delegate(ex, cause); | |
Raven.captureException(ex, {extra: {cause: cause}}); | |
}; | |
} | |
angular.module('ngRaven', []) | |
.config(['$provide', ngRavenProvider]) | |
.value('Raven', Raven); | |
})(Raven, window.angular); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you please provide usage instructions? couldn't find any in the documentation