import { Injectable } from "@angular/core" ; import { HttpErrorResponse , HttpEvent , HttpHandler , HttpInterceptor , HttpRequest , HttpResponse } from "@angular/common/http" ; import { Observable , of } from "rxjs" ; import { catchError } from "rxjs/operators" ; import { LoggingService } from "./logging.service" ; @ Injectable ( ) export class LoggingInterceptor implements HttpInterceptor { constructor ( private loggingService ) { } intercept ( req , next ) { return next . handle ( req ) . pipe ( catchError ( ( err ) => { this . loggingService . log ( `Logging Interceptor: ${ err . error . message }` ) ; return of ( new HttpResponse ( { body : { message : err . error . message } } ) ) ; } ) ) ; } }