My code:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule, Injectable, Injector } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { Pro } from '@ionic/pro';
Pro.init('d84aec69', {
appVersion: '0.0.1'
})
@Injectable()
export class MyErrorHandler implements ErrorHandler {
ionicErrorHandler: IonicErrorHandler;
constructor(injector: Injector) {
try {
this.ionicErrorHandler = injector.get(IonicErrorHandler);
} catch(e) {
// Unable to get the IonicErrorHandler provider, ensure
// IonicErrorHandler has been added to the providers list below
this.handleError(e);
console.log(e);
}
}
handleError(err: any): void {
Pro.monitoring.handleNewError(err);
// Remove this if you want to disable Ionic's auto exception handling
// in development mode.
this.ionicErrorHandler && this.ionicErrorHandler.handleError(err);
}
}
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: MyErrorHandler}
]
})
export class AppModule {}
I remove IonicErrorHandler from providers to catch the error
Output from console:
Ionic Pro initializing (app id: d84aec69)
main.js:sourcemap:133 Error: StaticInjectorError[IonicErrorHandler]:
StaticInjectorError[IonicErrorHandler]:
NullInjectorError: No provider for IonicErrorHandler!
at _NullInjector.get (vendor.js:sourcemap:1276)
at resolveToken (vendor.js:sourcemap:1564)
at tryResolveToken (vendor.js:sourcemap:1506)
at StaticInjector.get (vendor.js:sourcemap:1377)
at resolveToken (vendor.js:sourcemap:1564)
at tryResolveToken (vendor.js:sourcemap:1506)
at StaticInjector.get (vendor.js:sourcemap:1377)
at resolveNgModuleDep (vendor.js:sourcemap:10938)
at NgModuleRef_.get (vendor.js:sourcemap:12159)
at new MyErrorHandler (main.js:sourcemap:127)
Maybe I miss something or not understanding the concept.
screenshot of network activity:
Any help? Thanks!