Its unclear how to propagate errors to subscribers in REactiveX such that the Observable doesn't get destroyed.
Example
observable.onNext(1);
observable.onNext(2);
observable.onError("Nope");
observable.onNext(3);<<won't work.
I accept this restriction as it is, however I still have scenario where I want listeners downstream to know an error occured AND I don't want the observable to die.
The main use case for this is UI code that, if an error comes through, I don't want to have to call "Setup" against all the observables it previously registered with.
Possible alternatives are
a) push a custom object that has a data field and an error field
class Data
{
int value;
Error * error;
}
I don't like this solution
b) Have two streams. One for data and one for errors.
observable.onNext(1);
observable.onNext(2);
errorObservable.onNext("Error");
observable.onNext(3);
What are the best common practices for this?
I would definitely go with option A) - create an object that can carry both data and/or error. I doesn't matter how you will wrap the data and possible error into that object but sending both through one stream as onNext()
events is the right solution that gives to subscribers all info and all freedom to handle that.
The B) option might be quite challenging to implement in more complex asynchronous scenarios and would probably lead to use of a lot of Subject
s which is also bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With