I want to execute 2 network calls one after another. Both network calls return Observable. Second call uses data from successful result of the first call, method in successf
Have you looked into flatMap()? If your aversion to it (or zip()) is the need to make an unnecessary class just to hold two objects, android.util.Pair might be an answer. I'm not sure how to get exactly the error handling you're looking for, though.
API().auth(email, password)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.flatMap(new Func1>>() {
@Override
public Observable> call(AuthResponse authResponse) {
return API().getUser(authResponse.getAccessToken());
}
}, new Func2, Pair>>() {
@Override
public Pair> call(AuthResponse authResponse, List users) {
return new Pair<>(authResponse, users);
}
}).subscribe(new Action1>>() {
@Override
public void call(Pair> pair) {
doSomething(pair.first, pair.second);
}
}, new Action1() {
@Override
public void call(Throwable throwable) {
// not sure how to tell which one threw the error
}
});