From 8c5637ce8eec31db053b4f076d902c33bde302ba Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Mon, 26 Sep 2016 11:42:51 -0700 Subject: [PATCH 1/2] Update Angular 2 docs to reflect error handler API changes --- docs/integrations/angular2.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/integrations/angular2.rst b/docs/integrations/angular2.rst index 053200539093..2ef91f760827 100644 --- a/docs/integrations/angular2.rst +++ b/docs/integrations/angular2.rst @@ -3,8 +3,8 @@ Angular 2 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>`. -Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ExceptionHandler -`_ component. +Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ErrorHandler +`_ component. TypeScript Support @@ -61,20 +61,20 @@ Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts import Raven from 'raven-js'; import { bootstrap } from 'angular2/platform/browser'; import { MainApp } from './app.component'; - import { provide, ExceptionHandler } from 'angular2/core'; + import { provide, ErrorHandler } from 'angular2/core'; Raven .config('___PUBLIC_DSN___') .install(); - class RavenExceptionHandler { + class RavenErrorHandler { call(err:any) { Raven.captureException(err.originalException); } } bootstrap(MainApp, [ - provide(ExceptionHandler, {useClass: RavenExceptionHandler}) + provide(ErrorHandler, {useClass: RavenErrorHandler}) ]); Once you've completed these two steps, you are done. @@ -90,19 +90,19 @@ part of your `import` statement: import Raven = require('raven-js'); // NOTE: "require" not "from" import { bootstrap } from 'angular2/platform/browser'; import { MainApp } from './app.component'; - import { provide, ExceptionHandler } from 'angular2/core'; + import { provide, ErrorHandler } from 'angular2/core'; Raven .config('___PUBLIC_DSN___') .install(); - class RavenExceptionHandler { + class RavenErrorHandler { call(err:any) { Raven.captureException(err.originalException); } } bootstrap(MainApp, [ - provide(ExceptionHandler, {useClass: RavenExceptionHandler}) + provide(ErrorHandler, {useClass: RavenErrorHandler}) ]); From 49f38f937f4581a1625e4e7400b3da44bb6378b5 Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Mon, 26 Sep 2016 13:41:14 -0700 Subject: [PATCH 2/2] Fix example --- docs/integrations/angular2.rst | 54 ++++++++++------------------------ 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/docs/integrations/angular2.rst b/docs/integrations/angular2.rst index 2ef91f760827..48cdfc885176 100644 --- a/docs/integrations/angular2.rst +++ b/docs/integrations/angular2.rst @@ -54,55 +54,31 @@ First, configure SystemJS to locate the Raven.js package: } }); -Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts): +Then, in your main module file (where ``@NgModule`` is called, e.g. app.module.ts): .. code-block:: js - import Raven from 'raven-js'; - import { bootstrap } from 'angular2/platform/browser'; - import { MainApp } from './app.component'; - import { provide, ErrorHandler } from 'angular2/core'; + import Raven = require('raven-js'); + import { BrowserModule } from '@angular/platform-browser'; + import { AppComponent } from './app.component'; + import { NgModule, ErrorHandler } from 'angular2/core'; Raven .config('___PUBLIC_DSN___') .install(); - class RavenErrorHandler { - call(err:any) { - Raven.captureException(err.originalException); + class RavenErrorHandler implements ErrorHandler { + handleError(err:any) : void { + Raven.captureException(err.originalError); } } - bootstrap(MainApp, [ - provide(ErrorHandler, {useClass: RavenErrorHandler}) - ]); + @NgModule({ + imports: [ BrowserModule ], + declarations: [ AppComponent ], + bootstrap: [ AppComponent ], + providers: [ {provide: ErrorHandler, useClass: RavenErrorHandler}] + }) + export class AppModule { } Once you've completed these two steps, you are done. - -Webpack, Angular CLI, and Other Module Loaders -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In Webpack, Angular CLI, and other module loaders/packagers, you may need to use the **require** keyword as -part of your `import` statement: - -.. code-block:: js - - import Raven = require('raven-js'); // NOTE: "require" not "from" - import { bootstrap } from 'angular2/platform/browser'; - import { MainApp } from './app.component'; - import { provide, ErrorHandler } from 'angular2/core'; - - Raven - .config('___PUBLIC_DSN___') - .install(); - - class RavenErrorHandler { - call(err:any) { - Raven.captureException(err.originalException); - } - } - - bootstrap(MainApp, [ - provide(ErrorHandler, {useClass: RavenErrorHandler}) - ]); -