Project

General

Profile

1
import { environment } from 'src/environments/environment';
2
import { HttpErrorResponse } from '@angular/common/http';
3
import { ErrorHandlingService } from './../../shared/services/error-handling/error-handling.service';
4
import { ErrorHandler, Injectable, NgZone } from '@angular/core';
5

    
6
@Injectable()
7
export class GlobalErrorHandler implements ErrorHandler {
8
  constructor(private errorHandlingService: ErrorHandlingService, private zone: NgZone) {}
9

    
10
  handleError(error: Error): void {
11

    
12
    this.zone.run(() => {
13
      if (!(error instanceof HttpErrorResponse) && environment.enableGlobalErrorToast){
14
        this.errorHandlingService.showErrorMessage(error.message);
15
      }
16
    });
17

    
18

    
19
    console.error('Error from global error handler', error);
20
  }
21
}
(2-2/3)