import { ErrorHandler, Injectable, Injector } from '@angular/core'; import { DialogService } from '@arrow/bom/core'; import { WptDialog } from '@arrow/warpaint/dialog'; import { TranslateService } from '@ngx-translate/core'; @Injectable() export class GlobalErrorHandler implements ErrorHandler { private wptDialog: WptDialog; constructor(private injector: Injector, private dialogService: DialogService, private translate: TranslateService) {} handleError = (err: any) => { if(err.error?.customCode){ this._handleCustomError(err.error); return; } console.error(err); // This would display Modal Window with error message and OK button const { error, status, statusText } = err; this.dialogService.alert(this.translate.instant("Server Error"), error?.status?.statusMsg || this._getDefaultErrorMsg()); // Older approach, this would display Modal Window with generic message asking to Reload or Redirect to Management page // this.wptDialog = this.injector.get(WptDialog); // this.wptDialog.open(ErrorDialogComponent); }; private _handleCustomError(customError){ console.error("Custom Error", customError); this.dialogService.alert(this.translate.instant("Server Error"), customError.message || this._getDefaultErrorMsg()); } private _getDefaultErrorMsg(){ return this.translate.instant("Unexpected-error"); } }