Skip to content

Commit 7043839

Browse files
committed
First pass of angular.js plugin
1 parent c2a2e26 commit 7043839

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

plugins/angular.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Angular.js plugin
3+
*
4+
* Provides an $exceptionHandler for Angular.js
5+
*/
6+
;(function(Raven, angular) {
7+
'use strict';
8+
9+
// quit if angular isn't on the page
10+
if (!angular) {
11+
return;
12+
}
13+
14+
function ngRavenProvider($provide) {
15+
$provide.decorator('$exceptionHandler', [
16+
'RavenConfig, $delegate',
17+
ngRavenExceptionHandler
18+
]);
19+
}
20+
21+
function ngRavenExceptionHandler(RavenConfig, $delegate) {
22+
if (!RavenConfig)
23+
throw new Error('RavenConfig must be set before using this');
24+
25+
// Pop off DSN
26+
var DSN = RavenConfig.DSN;
27+
delete RavenConfig.DSN;
28+
29+
Raven.config(DSN, RavenConfig).install();
30+
return function angularExceptionHandler(ex, cause) {
31+
$delegate(ex, cause);
32+
Raven.captureException(ex, {extra: {cause: cause}});
33+
};
34+
}
35+
36+
angular.module('ngRaven', [])
37+
.config(['$provide', ngRavenProvider])
38+
.value('Raven', Raven);
39+
40+
})(Raven, window.angular);

0 commit comments

Comments
 (0)