import { Injectable , PLATFORM_ID , Inject } from '@angular/core' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { isPlatformBrowser } from '@angular/common' ; import { Observable , throwError } from 'rxjs' ; import { BaseService } from './base.service' ; @ Injectable ( { providedIn : 'root' } ) export class ErrorService extends BaseService { private isBrowser = isPlatformBrowser ( this . platformId ) ; constructor ( private _snack , @ Inject ( PLATFORM_ID ) private platformId ) { super ( ) ; } handleHttpError = ( error ) : Observable < any > => { const exception = error . error ; if ( this . isBrowser ) { if ( exception instanceof ErrorEvent ) { console . error ( exception . message ) ; } else { this . _snack . open ( exception . message , '' , this . getSnackbarConfig ( 'error' ) ) ; } } return throwError ( error ) ; } ; }