refactor: centralize unauthorized detection and simplify workspace rollback
This commit is contained in:
@@ -34,3 +34,8 @@ data class BoardsDrawerState(
|
||||
val isWorkspaceInteractionEnabled: Boolean = false,
|
||||
val isWorkspaceSwitchInFlight: Boolean = false,
|
||||
)
|
||||
|
||||
internal fun String.isUnauthorizedFailureMessage(): Boolean {
|
||||
val normalized = lowercase()
|
||||
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
||||
}
|
||||
|
||||
@@ -219,8 +219,7 @@ class BoardsRepository(
|
||||
}
|
||||
|
||||
private fun isUnauthorizedMessage(message: String): Boolean {
|
||||
val normalized = message.lowercase()
|
||||
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
||||
return message.isUnauthorizedFailureMessage()
|
||||
}
|
||||
|
||||
private fun isNetworkMessage(message: String): Boolean {
|
||||
|
||||
@@ -89,9 +89,6 @@ class BoardsViewModel(
|
||||
}
|
||||
|
||||
is BoardsApiResult.Failure -> {
|
||||
if (!currentWorkspaceId.isNullOrBlank()) {
|
||||
repository.switchWorkspace(currentWorkspaceId)
|
||||
}
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
drawer = it.drawer.copy(
|
||||
@@ -292,8 +289,3 @@ class BoardsViewModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.isUnauthorizedFailureMessage(): Boolean {
|
||||
val normalized = lowercase()
|
||||
return "401" in normalized || "403" in normalized || "authentication" in normalized || "unauthorized" in normalized
|
||||
}
|
||||
|
||||
@@ -316,6 +316,7 @@ class BoardsViewModelTest {
|
||||
|
||||
assertEquals("ws-1", viewModel.uiState.value.drawer.activeWorkspaceId)
|
||||
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
||||
assertEquals(1, api.listBoardsCalls)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -342,6 +343,7 @@ class BoardsViewModelTest {
|
||||
val event = eventDeferred.await()
|
||||
assertTrue(event is BoardsUiEvent.ForceSignOut)
|
||||
assertEquals("ws-1", sessionStore.getWorkspaceId())
|
||||
assertEquals(1, api.listBoardsCalls)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -364,6 +366,7 @@ class BoardsViewModelTest {
|
||||
|
||||
assertEquals(null, sessionStore.getWorkspaceId())
|
||||
assertEquals(null, viewModel.uiState.value.drawer.activeWorkspaceId)
|
||||
assertEquals(1, api.listBoardsCalls)
|
||||
}
|
||||
|
||||
private fun newViewModel(
|
||||
|
||||
Reference in New Issue
Block a user