Tour of Heroes Tutorial HTTP

tap operator: Looks at the observable values, does something with those values, and passes them along

//hero.service.ts

import { catchError, map, tap } from 'rxjs/operators';
...
getHeroes (): Observable {
  return this.http.get(this.heroesUrl)
    .pipe(
      tap(heroes => this.log(`fetched heroes`)),
      catchError(this.handleError('getHeroes', []))
    );
}

/** GET hero by id. Will 404 if id not found */
getHero(id: number): Observable {
  const url = `${this.heroesUrl}/${id}`;
  return this.http.get(url).pipe(
    tap(_ => this.log(`fetched hero id=${id}`)),
    catchError(this.handleError(`getHero id=${id}`))
  );
}
...
/**
 * Handle Http operation that failed.
 * Let the app continue.
 * @param operation - name of the operation that failed
 * @param result - optional value to return as the observable result
 */
private handleError (operation = 'operation', result?: T) {
  return (error: any): Observable => {
 
    // TODO: send the error to remote logging infrastructure
    console.error(error); // log to console instead
 
    // TODO: better job of transforming error for user consumption
    this.log(`${operation} failed: ${error.message}`);
 
    // Let the app keep running by returning an empty result.
    return of(result as T);
  };
}