Skip to content

Commit

Permalink
feat: エラーが発生した時にその操作をリトライできるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jan 11, 2024
1 parent 11d3be0 commit f902712
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import net.pantasystem.milktea.app_store.account.AccountStore
import net.pantasystem.milktea.app_store.handler.AppGlobalError
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorAction
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorStore
import net.pantasystem.milktea.common.Logger
import net.pantasystem.milktea.common.ResultState
Expand Down Expand Up @@ -118,14 +119,18 @@ class ClipListViewModel @Inject constructor(
clipItemState.clip,
savedStateHandle[ClipListNavigationImpl.EXTRA_ADD_TAB_TO_ACCOUNT_ID]
).onFailure {
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"ClipListViewModel.onToggleAddToTabButtonClicked",
AppGlobalError.ErrorLevel.Error,
StringSource.invoke("add/remove clip to tab failed"),
it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"ClipListViewModel.onToggleAddToTabButtonClicked",
AppGlobalError.ErrorLevel.Error,
StringSource.invoke("add/remove clip to tab failed"),
it
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
onToggleAddToTabButtonClicked(clipItemState)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import net.pantasystem.milktea.app_store.account.AccountStore
import net.pantasystem.milktea.app_store.handler.AppGlobalError
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorAction
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorStore
import net.pantasystem.milktea.common.*
import net.pantasystem.milktea.common_android.resource.StringSource
Expand Down Expand Up @@ -126,20 +127,25 @@ class ListListViewModel @Inject constructor(
userListRepository.syncOne(userList.id)
}.onFailure {
logger.error("toggle user failed", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"ListListViewModel.toggle",
AppGlobalError.ErrorLevel.Error,
StringSource(
if (userList.userIds.contains(userId)) {
"Remove user from list failed"
} else {
"Add user to list failed"
}
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"ListListViewModel.toggle",
AppGlobalError.ErrorLevel.Error,
StringSource(
if (userList.userIds.contains(userId)) {
"Remove user from list failed"
} else {
"Add user to list failed"
}
),
it,
true
),
it
),
)
UserActionAppGlobalErrorAction.Type.Retry
)
) {
toggle(userList, userId)
}
}
}
}
Expand All @@ -149,14 +155,18 @@ class ListListViewModel @Inject constructor(
viewModelScope.launch {
toggleAddToTabUseCase(ul.id, savedStateHandle[EXTRA_ADD_TAB_TO_ACCOUNT_ID]).onFailure {
logger.error("タブtoggle処理失敗", e = it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"ListListViewModel.toggleTab",
AppGlobalError.ErrorLevel.Error,
StringSource("add/remove tab failed"),
it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"ListListViewModel.toggleTab",
AppGlobalError.ErrorLevel.Error,
StringSource("add/remove tab failed"),
it
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
toggleTab(userList)
}
}
}
}
Expand All @@ -172,14 +182,19 @@ class ListListViewModel @Inject constructor(
logger.debug("作成成功")
}.onFailure {
logger.error("作成失敗", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"ListListViewModel.createUserList",
AppGlobalError.ErrorLevel.Error,
StringSource("create user list failed"),
it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"ListListViewModel.createUserList",
AppGlobalError.ErrorLevel.Error,
StringSource("create user list failed"),
it,
true
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
createUserList(name)
}
}
}

Expand Down

0 comments on commit f902712

Please sign in to comment.