[Chat] error log improvements (#679)
This commit is contained in:
Родитель
8a1a2acad4
Коммит
0d6e1164aa
|
@ -26,15 +26,6 @@ public final class ChatCompositeErrorEvent {
|
|||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link ChatCompositeErrorEvent} with error code and caused throwable.
|
||||
*
|
||||
* @param code Error code {@link ChatCompositeErrorCode}.
|
||||
*/
|
||||
public ChatCompositeErrorEvent(final String threadId, final ChatCompositeErrorCode code) {
|
||||
this(threadId, code, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cause of this throwable or {@code null} if the
|
||||
* cause is nonexistent or unknown. (The cause is the throwable that
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package com.azure.android.communication.ui.chat.presentation.ui.viewmodel
|
||||
|
||||
import android.content.Context
|
||||
import com.azure.android.communication.ui.chat.models.ChatCompositeErrorCode
|
||||
import com.azure.android.communication.ui.chat.models.ChatCompositeErrorEvent
|
||||
import com.azure.android.communication.ui.chat.models.MessageContextMenuModel
|
||||
import com.azure.android.communication.ui.chat.models.MessageInfoModel
|
||||
|
@ -34,7 +35,7 @@ internal data class ChatScreenViewModel(
|
|||
val messageContextMenu: MessageContextMenuModel,
|
||||
val sendMessageEnabled: Boolean = false,
|
||||
) {
|
||||
val showError get() = error != null
|
||||
val showError get() = error != null && error.errorCode == ChatCompositeErrorCode.JOIN_FAILED
|
||||
val errorMessage get() = error?.errorCode?.toString() ?: ""
|
||||
val isLoading get() = chatStatus != ChatStatus.INITIALIZED && !showError
|
||||
val unreadMessagesIndicatorVisibility = unreadMessagesCount > 0
|
||||
|
|
|
@ -69,7 +69,8 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
ErrorAction.ChatStateErrorOccurred(
|
||||
chatCompositeErrorEvent = ChatCompositeErrorEvent(
|
||||
threadId,
|
||||
ChatCompositeErrorCode.SEND_MESSAGE_FAILED
|
||||
ChatCompositeErrorCode.SEND_MESSAGE_FAILED,
|
||||
error
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -99,7 +100,8 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
ErrorAction.ChatStateErrorOccurred(
|
||||
chatCompositeErrorEvent = ChatCompositeErrorEvent(
|
||||
threadId,
|
||||
ChatCompositeErrorCode.SEND_MESSAGE_FAILED
|
||||
ChatCompositeErrorCode.SEND_MESSAGE_FAILED,
|
||||
error
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -122,7 +124,8 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
ErrorAction.ChatStateErrorOccurred(
|
||||
chatCompositeErrorEvent = ChatCompositeErrorEvent(
|
||||
threadId,
|
||||
ChatCompositeErrorCode.SEND_EDIT_MESSAGE_FAILED
|
||||
ChatCompositeErrorCode.SEND_EDIT_MESSAGE_FAILED,
|
||||
error
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -141,7 +144,8 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
ErrorAction.ChatStateErrorOccurred(
|
||||
chatCompositeErrorEvent = ChatCompositeErrorEvent(
|
||||
threadId,
|
||||
ChatCompositeErrorCode.SEND_READ_RECEIPT_FAILED
|
||||
ChatCompositeErrorCode.SEND_READ_RECEIPT_FAILED,
|
||||
error
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -164,7 +168,8 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
ErrorAction.ChatStateErrorOccurred(
|
||||
chatCompositeErrorEvent = ChatCompositeErrorEvent(
|
||||
threadId,
|
||||
ChatCompositeErrorCode.SEND_TYPING_INDICATOR_FAILED
|
||||
ChatCompositeErrorCode.SEND_TYPING_INDICATOR_FAILED,
|
||||
error,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -189,13 +194,13 @@ internal class ChatActionHandler(private val chatService: ChatService) {
|
|||
chatService.startEventNotifications()
|
||||
dispatch.invoke(ChatAction.FetchMessages())
|
||||
} catch (ex: Exception) {
|
||||
val error = ChatCompositeErrorEvent(threadId, ChatCompositeErrorCode.START_EVENT_NOTIFICATIONS_FAILED)
|
||||
val error = ChatCompositeErrorEvent(threadId, ChatCompositeErrorCode.START_EVENT_NOTIFICATIONS_FAILED, ex)
|
||||
dispatch(ErrorAction.ChatStateErrorOccurred(chatCompositeErrorEvent = error))
|
||||
}
|
||||
try {
|
||||
chatService.requestChatParticipants()
|
||||
} catch (ex: Exception) {
|
||||
val error = ChatCompositeErrorEvent(threadId, ChatCompositeErrorCode.REQUEST_PARTICIPANTS_FETCH_FAILED)
|
||||
val error = ChatCompositeErrorEvent(threadId, ChatCompositeErrorCode.REQUEST_PARTICIPANTS_FETCH_FAILED, ex)
|
||||
dispatch(ErrorAction.ChatStateErrorOccurred(chatCompositeErrorEvent = error))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,11 @@ internal interface ErrorReducer : Reducer<ErrorState>
|
|||
internal class ErrorReducerImpl : ErrorReducer {
|
||||
override fun reduce(state: ErrorState, action: Action): ErrorState {
|
||||
when (action) {
|
||||
is ErrorAction.ChatStateErrorOccurred -> return state.copy(
|
||||
chatCompositeErrorEvent = action.chatCompositeErrorEvent
|
||||
)
|
||||
is ErrorAction.ChatStateErrorOccurred -> {
|
||||
return state.copy(
|
||||
chatCompositeErrorEvent = action.chatCompositeErrorEvent
|
||||
)
|
||||
}
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
@ -16,7 +17,6 @@ import androidx.activity.addCallback
|
|||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.get
|
||||
import com.azure.android.communication.ui.callingcompositedemoapp.BuildConfig
|
||||
import com.azure.android.communication.ui.callingcompositedemoapp.R
|
||||
import com.azure.android.communication.ui.callingcompositedemoapp.databinding.ActivityChatLauncherBinding
|
||||
|
@ -233,11 +233,10 @@ class ChatLauncherActivity : AppCompatActivity() {
|
|||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun handleError(eventArgs: ChatCompositeErrorEvent) {
|
||||
println("================= application is logging error =====================")
|
||||
println(eventArgs.cause)
|
||||
println(eventArgs.errorCode)
|
||||
showAlert("${eventArgs.cause}")
|
||||
println("====================================================================")
|
||||
private fun handleError(errorEvent: ChatCompositeErrorEvent) {
|
||||
Log.e("ChatCompositeDemoApp", "================= application is logging error =====================")
|
||||
Log.e("ChatCompositeDemoApp", "${errorEvent.errorCode}", errorEvent.cause)
|
||||
showAlert("${errorEvent.errorCode} : ${errorEvent.cause}")
|
||||
Log.e("ChatCompositeDemoApp", "====================================================================")
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче