Observable errors
So 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:
interface IValue {
value: number
}
interface INestedObj {
id?: IValue;
}
const objEmit : Observable<INestedObj> = of(
{ id: { value: 1 } },
{},
{ id: { value: 2 } }
);
Here, we start with two interfaces, named IValue
and INestedObj
. The IValue
interface has a property named value
of type number, and the INestedObj
has a single optional parameter named id
of type IValue
. We then create an Observable named objEmit
that emits three values. The first value has the nested structure described by the INestedObj
interface, and the second is a blank object. Now consider the following Observable stream:
const returnIdValue = objEmit.pipe(
map((value: INestedObj) => {
return...