Problem
Suppose there is a Http request observable that errored, we can just retry it. But I also want the UI to inform the user that this resource failed to load. What is the best architecture?
Intended Behavior for the Target Observable
- Retry-able.
- Long-running. Doesn't complete or error.
- Shared. Does not generate unnecessary requests when multiple subscriber.
- Load on need. Does not generate unnecessary requests when not subscribed.
- Inform UI of the errors.
(3 and 4 can be achieved by shareReplay({bufferSize: 1, refCount: true})
)
My Attempts
I think it's best to pass an error message to the downstream observer while keeping retrying the source. It causes minimum changes to the architecture. But I didn't see a way I can do it with Rxjs, because
retry()
always intercepts the error. If you materialze the error, thenretry()
won't retry. If not, then no error will propagate to the downstream.catchError()
without rethrowing will always complete the stream.
Although let the UI observer tap(,,onError)
and retry()
can satisfy this need, but I think it is dangerous to let the UI take this responsibility. And multiple UI observer means a LOT of duplicated retries.