Error Handling
- We use the
catchError operator to catch the error
- We can create a general error handling method that can process the error internally while surfacing a user friendly error via
throwError
private handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
console.error('An error occurred:', error.error.message);
} else {
console.error('Error Status: ', error.status);
console.error('Error Details: ', error.error);
}
return throwError('Something bad happened; please try again later.');
};