add Error Handler
This commit is contained in:
parent
856b553da2
commit
482ca40d48
|
@ -821,6 +821,9 @@ ipcMain.on(ClipboardChannel.Read, (event: IpcMainEvent, ...args: any[]) => {
|
||||||
ipcMain.on(AppChannel.Exit, (event: IpcMainEvent, ...args: any[]) => {
|
ipcMain.on(AppChannel.Exit, (event: IpcMainEvent, ...args: any[]) => {
|
||||||
appExit();
|
appExit();
|
||||||
});
|
});
|
||||||
|
ipcMain.on(AppChannel.Logging, (event: IpcMainEvent, ...args: any[]) => {
|
||||||
|
log.error('[G]', args[0]);
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on(ExternalChannel.OpenUrl, (event: IpcMainEvent, ...args: any[]) => {
|
ipcMain.on(ExternalChannel.OpenUrl, (event: IpcMainEvent, ...args: any[]) => {
|
||||||
const targetUrl = args[0];
|
const targetUrl = args[0];
|
||||||
|
|
|
@ -50,6 +50,7 @@ import { AppMessengerLayoutModule } from './layouts/messenger/messenger.layout.m
|
||||||
import { AppNativeLayoutModule } from './layouts/native/native.layout.module';
|
import { AppNativeLayoutModule } from './layouts/native/native.layout.module';
|
||||||
|
|
||||||
import { environment } from '../environments/environment';
|
import { environment } from '../environments/environment';
|
||||||
|
import { ERRORHANDLER } from './error-handler';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -105,7 +106,7 @@ import { environment } from '../environments/environment';
|
||||||
level: NgxLoggerLevel.DEBUG
|
level: NgxLoggerLevel.DEBUG
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
providers: [...GUARDS],
|
providers: [...GUARDS, ERRORHANDLER],
|
||||||
declarations: [AppComponent],
|
declarations: [AppComponent],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
entryComponents: []
|
entryComponents: []
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { AppGlobalErrorhandler } from './global.errorhandler';
|
||||||
|
import { ErrorHandler } from '@angular/core';
|
||||||
|
|
||||||
|
export const ERRORHANDLER = [
|
||||||
|
{ provide: ErrorHandler, useClass: AppGlobalErrorhandler }
|
||||||
|
];
|
|
@ -234,6 +234,9 @@ export class BrowserNativeService extends NativeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
appExit(): void {}
|
appExit(): void {}
|
||||||
|
appLogging(error: any): void {
|
||||||
|
console.error('[G]', error);
|
||||||
|
}
|
||||||
|
|
||||||
zoomTo(factor: number): Promise<number> {
|
zoomTo(factor: number): Promise<number> {
|
||||||
return new Promise<number>((resolve, reject) => {
|
return new Promise<number>((resolve, reject) => {
|
||||||
|
|
|
@ -414,6 +414,9 @@ export class ElectronNativeService implements NativeService {
|
||||||
appExit(): void {
|
appExit(): void {
|
||||||
this.ipcRenderer.send(AppChannel.Exit);
|
this.ipcRenderer.send(AppChannel.Exit);
|
||||||
}
|
}
|
||||||
|
appLogging(error: any): void {
|
||||||
|
this.ipcRenderer.send(AppChannel.Logging, error);
|
||||||
|
}
|
||||||
|
|
||||||
zoomTo(factor: number): Promise<number> {
|
zoomTo(factor: number): Promise<number> {
|
||||||
return new Promise<number>((resolve, reject) => {
|
return new Promise<number>((resolve, reject) => {
|
||||||
|
|
|
@ -61,7 +61,8 @@ export enum ClipboardChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AppChannel {
|
export enum AppChannel {
|
||||||
Exit = 'UCAP::app::exit'
|
Exit = 'UCAP::app::exit',
|
||||||
|
Logging = 'UCAP::app::logging'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ExternalChannel {
|
export enum ExternalChannel {
|
||||||
|
|
|
@ -76,6 +76,7 @@ export abstract class NativeService {
|
||||||
abstract getWindowState(): WindowState;
|
abstract getWindowState(): WindowState;
|
||||||
abstract zoomTo(factor: number): Promise<number>;
|
abstract zoomTo(factor: number): Promise<number>;
|
||||||
abstract appExit(): void;
|
abstract appExit(): void;
|
||||||
|
abstract appLogging(error: any): void;
|
||||||
|
|
||||||
abstract idleStateChanged(): Observable<WindowIdle>;
|
abstract idleStateChanged(): Observable<WindowIdle>;
|
||||||
abstract idleStateStop(): void;
|
abstract idleStateStop(): void;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user