Skip to content

Improve Angular plugin + add docs #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/integrations/angular.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
AngularJS
=========

Installation
------------

Start by adding the ``raven.js`` script tag to your page. It should go **before** your application code.

Example:

.. sourcecode:: html

<script src="https://cdn.ravenjs.com/1.2.0/angular,native/raven.min.js"></script>

<!-- your application code below -->
<script src="static/app.js"></script>

Additionally, inside your main Angular application module, you need to declare ``ngRaven`` as a
module dependency:

.. code-block:: javascript

var myApp = angular.module('myApp', [
'ngRaven',
'ngRoute',
'myAppControllers',
'myAppFilters'
]);

Configuring the Client
----------------------

You need to configure raven.js to use your Sentry DSN. This should happen immediately after
your raven.js script include:

.. code-block:: html

<script src="https://cdn.ravenjs.com/1.2.0/angular,native/raven.min.js"></script>
<script>
Raven.config('___PUBLIC_DSN___').install();
</script>

At this point, Raven is ready to capture any uncaught exception via standard hooks
in addition to Backbone specific hooks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dis too

9 changes: 9 additions & 0 deletions docs/sentry-doc-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
"index#reporting-errors"
]
},
"javascript.angular": {
"name": "Angular",
"type": "framework",
"doc_link": "integrations/angular/",
"wizard": [
"integrations/angular#installation",
"integrations/angular#configuring-the-client"
]
},
"javascript.backbone": {
"name": "Backbone",
"type": "framework",
Expand Down
39 changes: 18 additions & 21 deletions plugins/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,30 @@ var angular = window.angular,
// quit if angular isn't on the page
if (!(angular && Raven)) return;

// Angular plugin doesn't go through the normal `Raven.addPlugin`
// since this bootstraps the `install()` automatically.

function ngRavenProvider($provide) {
$provide.decorator('$exceptionHandler', [
'RavenConfig', '$delegate',
ngRavenExceptionHandler
]);
function RavenProvider() {
this.$get = ['$window', function($window, $log) {
return $window.Raven;
}];
}

function ngRavenExceptionHandler(RavenConfig, $delegate) {
if (!RavenConfig)
throw new Error('RavenConfig must be set before using this');

if (RavenConfig.debug !== void 0) {
Raven.debug = RavenConfig.debug;
}
function ExceptionHandlerProvider($provide) {
$provide.decorator('$exceptionHandler',
['Raven', '$delegate', exceptionHandler]);
}

Raven.config(RavenConfig.dsn, RavenConfig.config).install();
return function angularExceptionHandler(ex, cause) {
function exceptionHandler(Raven, $delegate) {
return function (ex, cause) {
Raven.captureException(ex, {
extra: { cause: cause }
});
$delegate(ex, cause);
Raven.captureException(ex, {extra: {cause: cause}});
};
}

angular.module('ngRaven', [])
.config(['$provide', ngRavenProvider])
.value('Raven', Raven);
Raven.addPlugin(function () {
angular.module('ngRaven', [])
.provider('Raven', RavenProvider)
.config(['$provide', ExceptionHandlerProvider]);
});

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