Skip to content

Commit dca67ee

Browse files
committed
Merge pull request #405 from getsentry/angular-fixes
Improve Angular plugin + add docs
2 parents 32965d9 + 38d5107 commit dca67ee

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

docs/integrations/angular.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
AngularJS
2+
=========
3+
4+
Installation
5+
------------
6+
7+
Start by adding the ``raven.js`` script tag to your page. It should go **before** your application code.
8+
9+
Example:
10+
11+
.. sourcecode:: html
12+
13+
<script src="https://cdn.ravenjs.com/1.2.0/angular,native/raven.min.js"></script>
14+
15+
<!-- your application code below -->
16+
<script src="static/app.js"></script>
17+
18+
Additionally, inside your main Angular application module, you need to declare ``ngRaven`` as a
19+
module dependency:
20+
21+
.. code-block:: javascript
22+
23+
var myApp = angular.module('myApp', [
24+
'ngRaven',
25+
'ngRoute',
26+
'myAppControllers',
27+
'myAppFilters'
28+
]);
29+
30+
Configuring the Client
31+
----------------------
32+
33+
You need to configure raven.js to use your Sentry DSN. This should happen immediately after
34+
your raven.js script include:
35+
36+
.. code-block:: html
37+
38+
<script src="https://cdn.ravenjs.com/1.2.0/angular,native/raven.min.js"></script>
39+
<script>
40+
Raven.config('___PUBLIC_DSN___').install();
41+
</script>
42+
43+
At this point, Raven is ready to capture any uncaught exception via standard hooks
44+
in addition to Backbone specific hooks.

docs/sentry-doc-config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
"index#reporting-errors"
1111
]
1212
},
13+
"javascript.angular": {
14+
"name": "Angular",
15+
"type": "framework",
16+
"doc_link": "integrations/angular/",
17+
"wizard": [
18+
"integrations/angular#installation",
19+
"integrations/angular#configuring-the-client"
20+
]
21+
},
1322
"javascript.backbone": {
1423
"name": "Backbone",
1524
"type": "framework",

plugins/angular.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,30 @@ var angular = window.angular,
1212
// quit if angular isn't on the page
1313
if (!(angular && Raven)) return;
1414

15-
// Angular plugin doesn't go through the normal `Raven.addPlugin`
16-
// since this bootstraps the `install()` automatically.
17-
18-
function ngRavenProvider($provide) {
19-
$provide.decorator('$exceptionHandler', [
20-
'RavenConfig', '$delegate',
21-
ngRavenExceptionHandler
22-
]);
15+
function RavenProvider() {
16+
this.$get = ['$window', function($window, $log) {
17+
return $window.Raven;
18+
}];
2319
}
2420

25-
function ngRavenExceptionHandler(RavenConfig, $delegate) {
26-
if (!RavenConfig)
27-
throw new Error('RavenConfig must be set before using this');
28-
29-
if (RavenConfig.debug !== void 0) {
30-
Raven.debug = RavenConfig.debug;
31-
}
21+
function ExceptionHandlerProvider($provide) {
22+
$provide.decorator('$exceptionHandler',
23+
['Raven', '$delegate', exceptionHandler]);
24+
}
3225

33-
Raven.config(RavenConfig.dsn, RavenConfig.config).install();
34-
return function angularExceptionHandler(ex, cause) {
26+
function exceptionHandler(Raven, $delegate) {
27+
return function (ex, cause) {
28+
Raven.captureException(ex, {
29+
extra: { cause: cause }
30+
});
3531
$delegate(ex, cause);
36-
Raven.captureException(ex, {extra: {cause: cause}});
3732
};
3833
}
3934

40-
angular.module('ngRaven', [])
41-
.config(['$provide', ngRavenProvider])
42-
.value('Raven', Raven);
35+
Raven.addPlugin(function () {
36+
angular.module('ngRaven', [])
37+
.provider('Raven', RavenProvider)
38+
.config(['$provide', ExceptionHandlerProvider]);
39+
});
4340

4441
}(typeof window !== 'undefined' ? window : this));

0 commit comments

Comments
 (0)