Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import coil3.network.HttpException
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -314,6 +315,8 @@ class HomeScreenViewModel(
else throw NetworkException()
} else
loadPage(title = null, random = true)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
if (e is NetworkException) {
backStack.add(
Expand Down Expand Up @@ -482,6 +485,8 @@ class HomeScreenViewModel(
_homeScreenState.update { currentState ->
currentState.copy(isLoading = false)
}
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e("ViewModel", "Error in fetching results: ${e.message}")
e.printStackTrace()
Expand Down Expand Up @@ -607,6 +612,8 @@ class HomeScreenViewModel(
_homeScreenState.update { currentState ->
currentState.copy(isLoading = false)
}
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e("ViewModel", "Error in loading feed: ${e.message}")
backStack[0] = HomeSubscreen.Logo
Expand Down Expand Up @@ -673,6 +680,8 @@ class HomeScreenViewModel(
(backStack[lastIndex] as HomeSubscreen.Article).copy(savedStatus = SavedStatus.SAVED)

return WRStatus.SUCCESS
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e("ViewModel", "Cannot save article, network error")
e.printStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.AP
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -203,6 +204,8 @@ class SettingsViewModel(
preferencesStateMutableFlow.update {
PreferencesState()
}
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Log.e("ViewModel", "Error in restoring settings: ${e.message}")
e.printStackTrace()
Expand Down