Came across an rxjs issue I can't seem to quite get. basically I have two requests:
const obs1$ = this.http.get('route-1')
const obs2$ = this.http.get('route-2')
if obs1$ emits an error, i want to catch it and just emit a static value. but if obs1$ completes, I want to switch into obs2$ and not catch errors from obs2$. I have it working like this:
obs1$.pipe(
catchError(() => of('my value')),
switchMap((v) => v === 'my value' ? of(v) : obs2$)
).subscribe(
(v) => console.log(v, 'got my result'),
(e) => console.log(e, 'got an error')
)
but this seems a little messy and I'm wondering if there's a better way to achieve this. I can't move the catchError after the switchMap cause then i'll be catching errors from obs2$ as well which I do not want. I just want to skip to the end if i get an error from obs1$