but how should I do the catch block where it sees ...
# rx
u
but how should I do the catch block where it sees the messageId param?
k
Copy code
messageRepository
.insertSendingTextMessage(...)
  .flatMap { messageId ->
    apiClient.postMessage(...)
      .flatMap{ apiMessage -> messageRepository.updateSentMessageAndParents(apiMessage) }
      .onErrorResumeNext { error -> 
        messageRepository.updateMessageState(messageId, MessageState.ERROR) }
        .flatMap{ Observable.error(error) }
      }// ONLY if you want to trigger the error but My suggestion would be to return a Succes() / Error() sealed class.
  }
the
.flatMap{ Observable.error(error) }
at the end is there only because when you catch an exception you also throw it again. but it is up to you if you want to keep it or not 🙂
u
Yea nesting, I thought about that. Thanks. Btw now, how would you add the
if (messageId != null) messageRepository.updateMessageState(messageId, MessageState.ERROR)
catch?
just throw from the
insertSendingTextMessage
, right?
k
right now if
insertSendingTextMessage
fails, it never executes the inner part so the
onErrorResumeNext { updateMessageState() }
never gets called.
u
yes, nesting for visiblity gave it to you automatically, nice, thanks
k
yes exactly as you said, any time 👍