Stephan Kristyn Stephan Kristyn - 2 months ago 15
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:

this.userService.saveUser(this.user)
.map((res:any) => {


which does not work (code execution does halt).

Answer

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});
Comments