22 lines
775 B
TypeScript
22 lines
775 B
TypeScript
import { environment } from 'src/environments/environment';
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
import { ErrorHandlingService } from './../../shared/services/error-handling/error-handling.service';
|
|
import { ErrorHandler, Injectable, NgZone } from '@angular/core';
|
|
|
|
@Injectable()
|
|
export class GlobalErrorHandler implements ErrorHandler {
|
|
constructor(private errorHandlingService: ErrorHandlingService, private zone: NgZone) {}
|
|
|
|
handleError(error: Error): void {
|
|
|
|
this.zone.run(() => {
|
|
if (!(error instanceof HttpErrorResponse) && environment.enableGlobalErrorToast){
|
|
this.errorHandlingService.showErrorMessage(error.message);
|
|
}
|
|
});
|
|
|
|
|
|
console.error('Error from global error handler', error);
|
|
}
|
|
}
|