July 2018
Intermediate to advanced
420 pages
8h 46m
English
Now, let's add the error handling for the bikes service. Add the following code, right after the voteOnBike() function:
/** Error handler */
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side error.
console.error('An error occurred:', error.error.message);
} else {
// The backend error.
return throwError(error);
}
// return a custom error message
return throwError('Something bad happened; please try again later.');
}
As we can see, the handleError() function on the bike service is the same as the authentication service, and will be the same on the builders service. Whenever you need to write the same code more than once, it is highly recommended that ...
Read now
Unlock full access