import { ErrorObservable } from 'rxjs/observable/ErrorObservable'; import { Response } from '@angular/http'; import { IErrorHandler } from './error-handler.interface'; import { IApiErrorHandler } from './api-error-handler.interface'; export class ErrorHandlerService implements IErrorHandler { public constructor( private apiErrorHandler: IApiErrorHandler, private fallbackErrorHandler: IErrorHandler, ) {} public handle(error?: any): ErrorObservable { if (error instanceof Response) { return this.apiErrorHandler.handle(error); } return this.fallbackErrorHandler.handle(error); } }