Observable Errors
Learn how to catch errors in an Observable stream, including how to use catchError within an Observable stream itself.
We'll cover the following...
Observable exceptions
What happens when something goes wrong within an Observable stream?
Obviously, we will need a mechanism to catch these errors so that we can do something sensible with them.
As an example of a faulty Observable stream, consider the following code:
Here, we start with two interfaces named IValue and INestedObj.
-
The
IValueinterface on lines 2 – 4 has a property namedvalueof typenumber. -
The
INestedObjinterface on lines 7 – 9 has a single optional parameter namedidof typeIValue. -
We then create an Observable named
objEmiton lines 12–16 that emits three values:- The first value has the nested structure described by the
INestedObjinterface. - The second is a blank object.
- The third value also has the nested structure described by the
INestedObjinterface.
- The first value has the nested structure described by the
Now, consider the following Observable stream:
-
We have an Observable stream named
returnIdValueon lines 4–8 ...