Simplify error handling
This commit is contained in:
@@ -6,6 +6,7 @@ import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import gq.kirmanak.mealient.data.auth.AuthRepo
|
||||
import gq.kirmanak.mealient.extensions.runCatchingExceptCancel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.combine
|
||||
@@ -40,7 +41,7 @@ class AuthenticationViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun authenticate(username: String, password: String): Result<Unit> = runCatching {
|
||||
suspend fun authenticate(username: String, password: String) = runCatchingExceptCancel {
|
||||
authRepo.authenticate(username, password)
|
||||
}.onFailure {
|
||||
Timber.e(it, "authenticate: can't authenticate")
|
||||
|
||||
@@ -9,6 +9,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import gq.kirmanak.mealient.data.recipes.RecipeImageLoader
|
||||
import gq.kirmanak.mealient.data.recipes.RecipeRepo
|
||||
import gq.kirmanak.mealient.data.recipes.impl.FullRecipeInfo
|
||||
import gq.kirmanak.mealient.extensions.runCatchingExceptCancel
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
@@ -41,7 +42,7 @@ constructor(
|
||||
recipeIngredientsAdapter.submitList(null)
|
||||
recipeInstructionsAdapter.submitList(null)
|
||||
viewModelScope.launch {
|
||||
runCatching { recipeRepo.loadRecipeInfo(recipeId, recipeSlug) }
|
||||
runCatchingExceptCancel { recipeRepo.loadRecipeInfo(recipeId, recipeSlug) }
|
||||
.onSuccess {
|
||||
Timber.d("loadRecipeInfo: received recipe info = $it")
|
||||
_recipeInfo.value = it
|
||||
|
||||
Reference in New Issue
Block a user