Angular · Middle · Question 20 of 75
Why should catchError be placed inside switchMap in a long-lived stream?
this.query$.pipe(
switchMap((q) => this.api.search(q).pipe(catchError(() => of([])))),
);- ✓Correct answer: An error completes the stream it reaches; catching it on the inner Observable keeps the outer search stream alive
- 2
catchErroronly works insideswitchMap - 3It makes the request retry automatically
Explanation
If the error reaches the outer stream, it terminates and the search box stops working after the first failure. Handle errors per request and return a fallback value.