import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor , HTTP_INTERCEPTORS } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import 'rxjs/add/observable/throw' ; import 'rxjs/add/operator/catch' ; @ Injectable ( ) export class ErrorInterceptor implements HttpInterceptor { intercept ( request , next ) { return next . handle ( request ) . catch ( errorResponse => { return Observable . throw ( errorResponse . error ) ; } ) ; } } export const ErrorInterceptorProvider = { provide : HTTP_INTERCEPTORS , useClass : ErrorInterceptor , multi : true , } ;