Stephan Kristyn Stephan Kristyn - 1 year ago 148
TypeScript Question

Subscribe to already mapped Observable in Angular 2 and catch error

this.userService.saveUser(this.user).subscribe(response => {

Given above Code, how can I catch an error when I make use of above returned service, e.g:

I tried:

.map((res:any) => {

which does not work (code execution does halt).

Answer Source

The error is the second parameter in the subscribe function.

Your code would be the following:

this.userService.saveUser(this.user).subscribe(response => {
 error => {your code});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download