Skip to content

Commit ace7984

Browse files
committed
added classes for tracekit reporting
1 parent 7445002 commit ace7984

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

app/app.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
import {ExceptionHandler, provide} from 'angular2/core';
12
import 'es6-shim';
23
import {App, Platform} from 'ionic-angular';
34
import {StatusBar} from 'ionic-native';
45
import {TabsPage} from './pages/tabs/tabs';
5-
6+
import {CustomExceptionHandler} from './util/customExceptionHandler';
7+
import {ErrorReporter} from './util/errorReporter';
68

79
@App({
810
template: '<ion-nav [root]="rootPage"></ion-nav>',
11+
providers: [ErrorReporter, [provide(ExceptionHandler, {useClass:CustomExceptionHandler})]],
912
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
1013
})
1114
export class MyApp {
1215
rootPage: any = TabsPage;
1316

14-
constructor(platform: Platform) {
17+
constructor(platform: Platform, private er : ErrorReporter) {
1518
platform.ready().then(() => {
1619
// Okay, so the platform is ready and our plugins are available.
1720
// Here you can do any higher level native things you might need.
1821
StatusBar.styleDefault();
22+
23+
er.init();
1924
});
2025
}
2126
}

app/pages/page1/page1.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ <h2>Welcome to Ionic 2!</h2>
1212
Take a look at the <code>app/</code> directory to add or change tabs,
1313
update any existing page or create new pages.
1414
</p>
15+
<button (click)='test()'>Test Error</button>
1516
</ion-content>

app/pages/page1/page1.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ export class Page1 {
88
constructor() {
99

1010
}
11+
12+
test() {
13+
console.log('test button clicked');
14+
15+
throw new Error('oops');
16+
}
1117
}

app/util/customExceptionHandler.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Injectable} from 'angular2/core';
2+
3+
@Injectable()
4+
export class CustomExceptionHandler {
5+
call(error, stackTrace = null, reason = null) {
6+
console.log('custom exception handler...');
7+
console.error(error, [stackTrace, reason]);
8+
9+
// TraceKit.report(e); //error with stack trace gets normalized and sent to subscriber
10+
}
11+
}

app/util/errorReporter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Injectable} from 'angular2/core';
2+
3+
@Injectable()
4+
export class ErrorReporter {
5+
init(){
6+
// TraceKit.report.subscribe(this.reportError);
7+
console.log("ErrorReporter is initialized");
8+
}
9+
10+
reportError(error){
11+
// do something with the error
12+
}
13+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ionicons": "3.0.0-alpha.3",
99
"reflect-metadata": "0.1.2",
1010
"rxjs": "5.0.0-beta.0",
11+
"tracekit": "^0.3.4",
1112
"zone.js": "0.5.14"
1213
},
1314
"devDependencies": {

0 commit comments

Comments
 (0)