RxJava flatmap: how to check which observable emitted an error

I'm using RxJava's flatmap in order to execute multiple calls in sequence where one call relys on the previous call. I also need to know which observable emitted an error in the case that onError is called in order to properly implement my error handling. How do I achieve this?

Here is my code:

mSubscription = RxUtil.callObservable(mDataManager.createAccount(email, password))
            .flatMap(new Func1<AuthResult, Observable<Void>>() {
                public Observable<Void> call(AuthResult authResult) {

                    User user = new User(0, null, null, name, null, username, 0, 0);

                    return RxUtil.callObservable(mDataManager.createUser(authResult.getUser().getUid(), user));
            .subscribe(new Subscriber<Void>() {
                public void onCompleted() {


                public void onError(Throwable throwable) {
                    try {
                        throw (Exception) throwable;
                    } catch (FirebaseAuthUserCollisionException ucException) {
                    } catch (Exception exception) {

                public void onNext(Void aVoid) {

1 answer

  • answered 2018-02-13 01:46 Jacob Stinson

    I was thinking about this the wrong way. Is summary, I thought this was an issue that I needed to address when i didn't. RxJava will emit all errors in the onError method no matter what observable emits the error. Once onError is called the subscription is done, so the flatmap call will never take place.

    In summary, all I need to do is handle my errors from both observables I call (the original and the one in the flatmap) in the same onError method.