import { HttpErrorResponse , HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Observable , throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; implements HttpInterceptor class @ Injectable ( ) export class AppHttpInterceptorService implements HttpInterceptor { constructor ( ) { } public intercept ( req , next ) { return next . handle ( req ) . pipe ( catchError ( err => { if ( err instanceof HttpErrorResponse ) { this . onError ( err ) ; } return throwError ( err ) ; } ) ) ; } param response private onError ( response ) { const clientErrorMessage = this . handleClientSideError ( response . status ) ; if ( clientErrorMessage ) { return ; } const serverErrorMessage = this . handleServerError ( response . error ) ; if ( serverErrorMessage ) { } } private handleClientSideError ( status ) { switch ( status ) { case 0 : return 'NO INTERNET CONNECTION' ; case 404 : return 'REQUEST FAILURE' ; default : return ; } } private handleServerError ( errorResponse ) { return '' ; } }