Catching Errors With the Catch Operator

Learn how to respond when an error occurs and then continue the code execution.

So far we’ve learned how to detect an error and do something with that information, but we haven’t been able to react to it and continue with whatever we were doing. Observable instances have the catch operator, which allows us to react to an error in the Observable and continue with another Observable.

The catch operator takes either an Observable or a function, which receives the error as a parameter and returns another Observable. In our case, we want the Observable to emit a JSON object that contains an error property if there were errors in the original Observable:

Get hands-on with 1200+ tech skills courses.