import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor } from '@angular/common/http' ; import { Observable , throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { AlertService } from '@app/_services' ; @ Injectable ( ) export class ErrorInterceptor implements HttpInterceptor { constructor ( private alertService ) { } intercept ( request , next ) { return next . handle ( request ) . pipe ( catchError ( err => { const error = err . error ?. message || err . statusText ; this . alertService . error ( error ) ; console . error ( err ) ; return throwError ( error ) ; } ) ) ; } }