I'm trying to understand the implementation of catchError over an Http request in the Angular official tutorial (Tour Of Heroes).
The code of the http request is this:
this.http.get<Hero[]>(this.heroesUrl)
.pipe(catchError(this.handleError<Hero[]>('getHeroes', [])));
Inside the catchError, it passes the handleError function, which is implemented like this (summarized)
private handleError<T>(operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
//Various operation with the error variable..
return of(result as T);
};
}
Since I'm new to TypeScript, I've tried to read documentation about this kind of syntax (and I've read also other questions about this piece of code), but I didn't find a reply: what does
return (error: any): Observable<T> => {
means? I don't understand how to read it: who valorize the error variable? How?
I read that catchError require a parameter that is a function with 2 parameters: err, which is the error, and caught, which is the source observable, but I don't see how error is valorized here. I supposed that in catchError I had to pass handleError(err, caught).