How do you perform Error handling?
If the request fails on the server or failed to reach the server due to network issues then HttpClient will return an error object instead of a successful reponse. In this case, you need to handle in the component by passing error object as a second callback to subscribe() method.
Let's see how it can be handled in the component with an example,
fetchUser() {this.userService.getProfile().subscribe((data: User) => this.userProfile = { ...data }, // success patherror => this.error = error // error path);}
It is always a good idea to give the user some meaningful feedback instead of displaying the raw error object returned from HttpClient.
April 12, 2022
506
Read more
What is Angular Framework?
November 04, 2022
AngularWhat is a Angular module?
November 03, 2022
AngularWhat are the steps to use animation module?
October 31, 2022
Angular