How can i track every error in app.component.ts in ionic 2

469 views Asked by At

I am using ionic 2. I want to track every error that occur in ionic 2 app.component.ts file .Is there any solution for this ?

Thanks in advance

1

There are 1 answers

2
Sampath On BEST ANSWER

You need to use IonicErrorHandler class for that.This is a global error handler.

The IonicErrorHandler intercepts the default Console error handling and displays runtime errors as an overlay when using Ionic's Dev Build Server.

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicErrorHandler } from 'ionic-angular';

@NgModule({
  providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }]
})
class AppModule {}

Now if you just do throw new Error('Im error') anywhere in your application, you will see your console message.

Here is a great article about it with custom error handling.