Skip to content

Commit

Permalink
Handle error state
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Jun 12, 2024
1 parent 80c0736 commit 1a75708
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ class MarketTopCoinsViewModel2(

init {
viewModelScope.launch(Dispatchers.Default) {
reload()
try {
reload()

viewState = ViewState.Success
viewState = ViewState.Success
} catch (e: Throwable) {
viewState = ViewState.Error(e)
}

emitState()
}
Expand All @@ -89,9 +93,13 @@ class MarketTopCoinsViewModel2(

viewModelScope.launch(Dispatchers.Default) {
currencyManager.baseCurrencyUpdatedFlow.collect {
reload()
try {
reload()

viewState = ViewState.Success
viewState = ViewState.Success
} catch (e: Throwable) {
viewState = ViewState.Error(e)
}

emitState()
}
Expand Down Expand Up @@ -146,9 +154,13 @@ class MarketTopCoinsViewModel2(
emitState()

viewModelScope.launch(Dispatchers.Default) {
reload()
try {
reload()

viewState = ViewState.Success
viewState = ViewState.Success
} catch (e: Throwable) {
viewState = ViewState.Error(e)
}

isRefreshing = false
emitState()
Expand Down

0 comments on commit 1a75708

Please sign in to comment.