Skip to content

Commit f9ccad3

Browse files
committed
refactor: better handling error cases
1 parent 5337b50 commit f9ccad3

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

app/src/main/java/to/bitkit/ui/settings/advanced/RgsServerViewModel.kt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,24 @@ class RgsServerViewModel @Inject constructor(
7373
_uiState.update { it.copy(isLoading = true) }
7474

7575
viewModelScope.launch(bgDispatcher) {
76-
runCatching {
77-
lightningRepo.restartWithRgsServer(url)
78-
.onSuccess {
79-
_uiState.update {
80-
val newState = it.copy(
81-
isLoading = false,
82-
connectionResult = Result.success(Unit),
83-
)
84-
computeState(newState)
85-
}
76+
lightningRepo.restartWithRgsServer(url)
77+
.onSuccess {
78+
_uiState.update {
79+
val newState = it.copy(
80+
isLoading = false,
81+
connectionResult = Result.success(Unit),
82+
)
83+
computeState(newState)
84+
}
85+
}
86+
.onFailure { e ->
87+
_uiState.update {
88+
it.copy(
89+
isLoading = false,
90+
connectionResult = Result.failure(e),
91+
)
8692
}
87-
.onFailure { error -> throw error }
88-
}.onFailure { e ->
89-
_uiState.update {
90-
it.copy(
91-
isLoading = false,
92-
connectionResult = Result.failure(e),
93-
)
9493
}
95-
}
9694
}
9795
}
9896

0 commit comments

Comments
 (0)