but how should I do the catch block where it sees the messageId param?
k
kioba
06/21/2019, 3:36 PM
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.
}
kioba
06/21/2019, 3:42 PM
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
ursus
06/21/2019, 3:55 PM
Yea nesting, I thought about that. Thanks. Btw now, how would you add the
if (messageId != null) messageRepository.updateMessageState(messageId, MessageState.ERROR)
catch?
ursus
06/21/2019, 3:56 PM
just throw from the
insertSendingTextMessage
, right?
k
kioba
06/21/2019, 3:58 PM
right now if
insertSendingTextMessage
fails, it never executes the inner part so the
onErrorResumeNext { updateMessageState() }
never gets called.
u
ursus
06/21/2019, 3:58 PM
yes, nesting for visiblity gave it to you automatically, nice, thanks