add Error Handler

This commit is contained in:
leejinho 2020-03-12 16:16:04 +09:00
parent 856b553da2
commit 482ca40d48
8 changed files with 47 additions and 2 deletions

View File

@ -821,6 +821,9 @@ ipcMain.on(ClipboardChannel.Read, (event: IpcMainEvent, ...args: any[]) => {
ipcMain.on(AppChannel.Exit, (event: IpcMainEvent, ...args: any[]) => {
appExit();
});
ipcMain.on(AppChannel.Logging, (event: IpcMainEvent, ...args: any[]) => {
log.error('[G]', args[0]);
});
ipcMain.on(ExternalChannel.OpenUrl, (event: IpcMainEvent, ...args: any[]) => {
const targetUrl = args[0];

View File

@ -50,6 +50,7 @@ import { AppMessengerLayoutModule } from './layouts/messenger/messenger.layout.m
import { AppNativeLayoutModule } from './layouts/native/native.layout.module';
import { environment } from '../environments/environment';
import { ERRORHANDLER } from './error-handler';
@NgModule({
imports: [
@ -105,7 +106,7 @@ import { environment } from '../environments/environment';
level: NgxLoggerLevel.DEBUG
})
],
providers: [...GUARDS],
providers: [...GUARDS, ERRORHANDLER],
declarations: [AppComponent],
bootstrap: [AppComponent],
entryComponents: []

View File

@ -0,0 +1,27 @@
import { ErrorHandler, Injectable, Injector, NgZone } from '@angular/core';
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
import { error } from 'console';
@Injectable()
export class AppGlobalErrorhandler implements ErrorHandler {
constructor(private injector: Injector, private zone: NgZone) {}
// tslint:disable-next-line: no-shadowed-variable
handleError(error: Error) {
let nativeLogging: any;
try {
const nativeService: NativeService = this.injector.get(
UCAP_NATIVE_SERVICE
);
nativeService.appLogging(error.stack);
nativeLogging = 'SUCCESS';
} catch (e) {
nativeLogging = e;
}
console.groupCollapsed('App Global Error Logging');
console.log('App log', error);
console.log('Native Logging', nativeLogging);
console.groupEnd();
}
}

View File

@ -0,0 +1,6 @@
import { AppGlobalErrorhandler } from './global.errorhandler';
import { ErrorHandler } from '@angular/core';
export const ERRORHANDLER = [
{ provide: ErrorHandler, useClass: AppGlobalErrorhandler }
];

View File

@ -234,6 +234,9 @@ export class BrowserNativeService extends NativeService {
}
appExit(): void {}
appLogging(error: any): void {
console.error('[G]', error);
}
zoomTo(factor: number): Promise<number> {
return new Promise<number>((resolve, reject) => {

View File

@ -414,6 +414,9 @@ export class ElectronNativeService implements NativeService {
appExit(): void {
this.ipcRenderer.send(AppChannel.Exit);
}
appLogging(error: any): void {
this.ipcRenderer.send(AppChannel.Logging, error);
}
zoomTo(factor: number): Promise<number> {
return new Promise<number>((resolve, reject) => {

View File

@ -61,7 +61,8 @@ export enum ClipboardChannel {
}
export enum AppChannel {
Exit = 'UCAP::app::exit'
Exit = 'UCAP::app::exit',
Logging = 'UCAP::app::logging'
}
export enum ExternalChannel {

View File

@ -76,6 +76,7 @@ export abstract class NativeService {
abstract getWindowState(): WindowState;
abstract zoomTo(factor: number): Promise<number>;
abstract appExit(): void;
abstract appLogging(error: any): void;
abstract idleStateChanged(): Observable<WindowIdle>;
abstract idleStateStop(): void;