From 2112f0c2da17ddb772406521e93ffde4e3db9bfe Mon Sep 17 00:00:00 2001 From: Renan S Moreira Date: Sat, 29 Jun 2019 18:35:05 -0400 Subject: [PATCH] Adding support to Ionic v4 IonicErrorHandler doesn't exist anymore in Ionic 4+. Instead, we need to use ErrorHandler from angular/core --- .../platforms/javascript/ionic.md | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/collections/_documentation/platforms/javascript/ionic.md b/src/collections/_documentation/platforms/javascript/ionic.md index 88f2ef09c5dc1..cea7df340bda1 100644 --- a/src/collections/_documentation/platforms/javascript/ionic.md +++ b/src/collections/_documentation/platforms/javascript/ionic.md @@ -64,6 +64,25 @@ class SentryIonicErrorHandler extends IonicErrorHandler { } ``` +Or `ErrorHandler` for Ionic v4: + +```javascript +import { ErrorHandler } from '@angular/core'; + +import * as Sentry from 'sentry-cordova'; + +class SentryIonicErrorHandler extends ErrorHandler { + handleError(error) { + super.handleError(error); + try { + Sentry.captureException(error.originalError || error); + } catch (e) { + console.error(e); + } + } +} +``` + Then change the `@NgModule{providers:[]}` in `app.module.ts` to: ```javascript @@ -72,7 +91,7 @@ Then change the `@NgModule{providers:[]}` in `app.module.ts` to: providers: [ StatusBar, SplashScreen, - // {provide: ErrorHandler, useClass: IonicErrorHandler} remove this, add next line + // {provide: ErrorHandler, useClass: IonicErrorHandler} remove this, add next line (for Ionic 4 this line doen't exist by default) {provide: ErrorHandler, useClass: SentryIonicErrorHandler} ] })