I'm reading this tutorial:
https://angular.io/tutorial/toh-pt6#error-handling
I cannot totally understand the error-handling
with the function: handleError
.
That function is used on this code snippet:
/** GET heroes from the server */
getHeroes (): Observable<Hero[]> {
return this.http.get<Hero[]>(this.heroesUrl)
.pipe(
tap(heroes => this.log(`fetched heroes`)),
catchError(this.handleError('getHeroes', []))
);
}
here is the handleError
function:
/**
* 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<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
// 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);
};
}
I don't understand what means:
return (error: any): Observable<T> => { ... }
?
is that something similar to:
return ((error: any): Observable<T>) => { ... }
?
I just want to know what's the source and the destiny of the function.
The more details you can provide about the logic of handleError
function, the better. I want to go deep on this.