Skip to content

Commit

Permalink
#137 / errorcode에 따라 state 객체 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
taeheeL committed Dec 6, 2023
1 parent 58adef9 commit a4159c2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/sopt/uni/presentation/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.data.entity.home.HomeInfo
import sopt.uni.data.repository.home.HomeRepository
import sopt.uni.data.repository.shortgame.ShortGameRepository
import sopt.uni.presentation.common.content.ErrorCodeState
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -33,6 +34,9 @@ class HomeViewModel @Inject constructor(
private var _roundResult = MutableLiveData("")
val roundResult: LiveData<String> = _roundResult

private val _errorState = MutableStateFlow<ErrorCodeState>(ErrorCodeState.NoError)
val errorState = _errorState.asStateFlow()

init {
fetchHomeInfo()
}
Expand All @@ -47,8 +51,12 @@ class HomeViewModel @Inject constructor(
_roundGameId.value = it.roundGameId
_shortGameEnabled.value = it.shortGame?.enable ?: false
Timber.e("viewmodel's shortGame : ${it.shortGame}")
}.onFailure {
Timber.e(it)
}.onFailure { errorCode ->
Timber.e("Exception : $errorCode")
if (errorCode is Exception && errorCode.message.toString() == "UE1008") {
Timber.e("No Token")
_errorState.value = ErrorCodeState.NoToken
}
}
}
}
Expand Down

0 comments on commit a4159c2

Please sign in to comment.