import { Injectable } from '@angular/core' ; import { HttpInterceptor , HttpRequest , HttpHandler , HttpEvent , HttpErrorResponse } from '@angular/common/http' ; import { Observable , throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { AlertService } from '../services/alert.service' ; @ Injectable ( ) export class HttpErrorInterceptor implements HttpInterceptor { constructor ( private alertService ) { } intercept ( request , next ) { return next . handle ( request ) . pipe ( catchError ( ( response ) => { this . alertService . error ( `${ response . status }: ${ response . message }` ) ; return throwError ( response ) ; } ) ) ; } }