How do I go about handling errors in my Angular components, instead of in my Angular services?
Currently my errors are caught in my services, but it would be great if the error is returned to the component for ease of logging.
I have done a lot of searching and testing, but cannot find a simple solution that works for me. I am hoping there is a simple solution to modifying my code below (be kind, I am a NEWB ;)).
I have a very straight forward setup:
In my Component:
ngOnInit() {
this.orders = this.authService.registerUser().subscribe(response => {
return response;
});
}
In my Service:
registerUser(user): Observable<any> {
return this.http
.post(this.apiUrl + 'users', this.user, httpOptions)
.pipe(catchError(this.handleError));
}
handleError(err) {
if (err instanceof HttpErrorResponse) {
// Server Side Error
return throwError(err);
} else {
// Client Side Error
return throwError(err);
}
}
Thank you in advance!