import { Injectable } from '@angular/core' ; import { HttpEvent , HttpInterceptor , HttpHandler , HttpRequest } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { environment } from '@env/environment' ; import { Logger } from '../logger.service' ; const log = new Logger ( 'ErrorHandlerInterceptor' ) ; /**
 * Adds a default error handler to all requests.
 */ @ Injectable ( ) export class ErrorHandlerInterceptor implements HttpInterceptor { intercept ( request , next ) { return next . handle ( request ) . pipe ( catchError ( error => this . errorHandler ( error ) ) ) ; } private errorHandler ( response ) { if ( ! environment . production ) { log . error ( 'Request error' , response ) ; } throw response ; } }