Reputation: 3914
if I have a case where I use Rxjava zip operator, let's say that it zip 4 different network calls. for example:
Observable.zip(networkCall1, networkCall2, networkCall3, networkCall4),
(model1, model2, model3, model4) ->
Mapper.getResult(model1, model2, model3, model4)).subscribe(result -> {
//do some work
});
now if the error handling depends on knowing which Observable that cause this error, how could I know the specific Observable which throw the error. is there any Rx way to know such thing without breaking the stream.
Upvotes: 0
Views: 1087
Reputation: 8227
To know which observable caused the error, you will need to annotate each observable.
Observable.zip(
networkCall1
.onErrorResumeNext( error -> Observable.error( new IllegalStateException( "stream1", error) ) ),
networkCall2
.onErrorResumeNext( error -> Observable.error( new IllegalStateException( "stream2", error) ) ),
networkCall3
.onErrorResumeNext( error -> Observable.error( new IllegalStateException( "stream3", error ) ) ),
networkCall4
.onErrorResumeNext( error -> Observable.error( new IllegalStateException( "stream4", error ) ) ) ),
(model1, model2, model3, model4) ->
Mapper.getResult(model1, model2, model3, model4)).subscribe(result -> {
//do some work
});
Then, in your error handler, handle the IllegalStateException
, unwrapping the stream name and the original error.
Upvotes: 4