import { Pipe , PipeTransform } from '@angular/core' ; import { HttpClient , HttpErrorResponse } from '@angular/common/http' ; import { Observable , of } from 'rxjs' ; import { catchError , map } from 'rxjs/operators' ; import { ProductContentPipe } from '@shared/product-content.pipe' ; @ Pipe ( { name : 'sharedGetContent' } ) export class GetContentPipe implements PipeTransform { constructor ( public httpClient ) { } param product param content getContent ( product , content ) { const pcPipe = new ProductContentPipe ( ) ; const _content = pcPipe . transform ( product , content ) ; if ( ! _content ) { of ( null ) ; } try { return this . httpClient . get ( _content . url ) . pipe ( map ( response => response ) ) . pipe ( catchError ( this . handleError ( ) ) ) ; } catch ( e ) { return of ( null ) ; } } transform ( product , content ) { if ( ! product || ! content ) { return null ; } return this . getContent ( product , content ) ; } returns private handleError ( ) { return ( error ) : Observable < any > => { return of ( null ) ; } ; } }