import { Injectable } from '@angular/core' ; import { HttpErrorResponse } from '@angular/common/http' ; import { Observable , of } from 'rxjs' ; import { ToastService } from './toast.service' ; @ Injectable ( { providedIn : 'root' } ) export class ExceptionService { constructor ( private toastService ) { } catchBadResponse : ( err : HttpErrorResponse | any ) => Observable < any > = ( err ) => { let emsg = '' ; if ( err . error instanceof Error ) { emsg = `An error occurred: ${ err . error . message }` ; } else { emsg = `Backend returned code ${ err . status }, body was: ${ err . body . error }` ; } this . toastService . activate ( `Error - Bad Response - ${ emsg }` ) ; return of ( false ) ; } ; }