|
| 1 | +Angular 2 |
| 2 | +========= |
| 3 | + |
| 4 | +On its own, Raven.js will report any uncaught exceptions triggered from your application. For advanced usage examples of Raven.js, please read :doc:`Raven.js usage <../usage>`. |
| 5 | + |
| 6 | +Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ExceptionHandler |
| 7 | +<https://angular.io/docs/js/latest/api/core/index/ExceptionHandler-class.html>`_ component. |
| 8 | + |
| 9 | +**Note**: This document assumes you are writing your Angular 2 project in TypeScript, and using `SystemJS |
| 10 | +<https://github.com/systemjs/systemjs>`_ as your module bundler. |
| 11 | + |
| 12 | + |
| 13 | +TypeScript Support |
| 14 | +~~~~~~~~~~~~~~~~~~ |
| 15 | + |
| 16 | +Raven.js ships with a `TypeScript declaration file |
| 17 | +<https://github.com/getsentry/raven-js/blob/master/typescript/raven.d.ts>`_, which helps static checking correctness of |
| 18 | +Raven.js API calls, and facilitates auto-complete in TypeScript-aware IDEs like Visual Studio Code. |
| 19 | + |
| 20 | + |
| 21 | +Installation |
| 22 | +------------ |
| 23 | + |
| 24 | +Raven.js should be installed via npm. |
| 25 | + |
| 26 | +.. code-block:: sh |
| 27 | +
|
| 28 | + $ npm install raven-js --save |
| 29 | +
|
| 30 | +
|
| 31 | +Configuration |
| 32 | +------------- |
| 33 | + |
| 34 | +First, configure SystemJS to locate the Raven.js package: |
| 35 | + |
| 36 | +.. code-block:: js |
| 37 | +
|
| 38 | + System.config({ |
| 39 | + packages: { |
| 40 | + /* ... existing packages above ... */ |
| 41 | + 'raven-js': { |
| 42 | + main: 'dist/raven.js' |
| 43 | + } |
| 44 | + }, |
| 45 | + paths: { |
| 46 | + /* ... existing paths above ... */ |
| 47 | + 'raven-js': 'node_modules/raven-js' |
| 48 | + } |
| 49 | + }); |
| 50 | +
|
| 51 | +Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts): |
| 52 | + |
| 53 | +.. code-block:: js |
| 54 | +
|
| 55 | + import Raven from 'raven-js'; |
| 56 | + import { bootstrap } from 'angular2/platform/browser'; |
| 57 | + import { MainApp } from './app.component'; |
| 58 | + import { provide, ExceptionHandler } from 'angular2/core'; |
| 59 | +
|
| 60 | + Raven |
| 61 | + .config('__PUBLIC_DSN__') |
| 62 | + .install(); |
| 63 | +
|
| 64 | + class RavenExceptionHandler { |
| 65 | + call(err:any) { |
| 66 | + Raven.captureException(err.originalException); |
| 67 | + } |
| 68 | + } |
| 69 | +
|
| 70 | + bootstrap(MainApp, [ |
| 71 | + provide(ExceptionHandler, {useClass: RavenExceptionHandler}) |
| 72 | + ]); |
| 73 | +
|
| 74 | +Once you've completed these two steps, you are done. |
0 commit comments