``` private fun doPostMessage(...) { var messa...
# rx
u
Copy code
private fun doPostMessage(...) {
    var messageId: Long? = null
    try {
		messageId = messageRepository.insertSendingTextMessage(...)

        val apiMessage = apiClient.postMessage(...)

        messageRepository.updateSentMessageAndParents(apiMessage)

    } catch (ex: Exception) {
        if (messageId != null) messageRepository.updateMessageState(messageId, MessageState.ERROR)
        throw ex
    }
}
k
if
messageRepository.insertSendingTextMessage(...)
fails you still crashing the app. without properly calling the
updateMessageState
u
Why? I'd catch it, update the updateMessageState with ERROR and rethrow as a signal downstream it failed
k
if
insertSendingTextMessage
fails you won’t set the
messageId
so
updateMessageState
will be called with an uninitialised variable
u
oh, yea, in that case the update is skipped, since messageId will be null, its pseudo code, sorry
👍 1