Skip to content

Commit

Permalink
[MOD/#8] 서버통신 Failure, Error 예외 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed May 12, 2023
1 parent 5e9e42a commit 3529471
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import org.android.go.sopt.util.binding.BindingActivity
import org.android.go.sopt.util.extension.setOnSingleClickListener
import org.android.go.sopt.util.extension.showSnackbar
import org.android.go.sopt.util.extension.showToast
import org.android.go.sopt.util.state.LocalUiState.Failure
import org.android.go.sopt.util.state.LocalUiState.Success
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Success

@AndroidEntryPoint
class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_login) {
Expand Down Expand Up @@ -47,6 +48,7 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
when (state) {
is Success -> navigateToMainScreen()
is Failure -> showSnackbar(binding.root, getString(R.string.wrong_input_msg))
is Error -> showSnackbar(binding.root, getString(R.string.unknown_error_msg))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlinx.coroutines.launch
import org.android.go.sopt.data.entity.remote.request.RequestPostSignInDto
import org.android.go.sopt.domain.model.User
import org.android.go.sopt.domain.repository.AuthRepository
import org.android.go.sopt.util.state.LocalUiState
import org.android.go.sopt.util.state.LocalUiState.Failure
import org.android.go.sopt.util.state.LocalUiState.Success
import org.android.go.sopt.util.state.RemoteUiState
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Success
import retrofit2.HttpException
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -20,8 +21,8 @@ import javax.inject.Inject
class LoginViewModel @Inject constructor(
private val authRepository: AuthRepository,
) : ViewModel() {
private val _loginState = MutableLiveData<LocalUiState>()
val loginState: LiveData<LocalUiState>
private val _loginState = MutableLiveData<RemoteUiState>()
val loginState: LiveData<RemoteUiState>
get() = _loginState

val _id = MutableLiveData("")
Expand All @@ -38,7 +39,7 @@ class LoginViewModel @Inject constructor(

private fun setupAutoLogin() {
if (authRepository.getAutoLogin() && authRepository.getSignedUpUser() != null) {
_loginState.value = Success
_loginState.value = RemoteUiState.Success
}
}

Expand Down Expand Up @@ -71,9 +72,17 @@ class LoginViewModel @Inject constructor(
}
.onFailure { t ->
if (t is HttpException) {
when (t.code()) {
CODE_INVALID_INPUT -> _loginState.value = Failure(CODE_INVALID_INPUT)
else -> _loginState.value = Error
}
Timber.e("POST SIGNIN FAIL ${t.code()} : ${t.message()}")
}
}
}
}

companion object {
const val CODE_INVALID_INPUT = 400
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.android.go.sopt.R
import org.android.go.sopt.databinding.FragmentFollowerBinding
import org.android.go.sopt.presentation.main.follower.FollowerAdapter.Companion.VIEW_TYPE_HEADER
import org.android.go.sopt.util.binding.BindingFragment
import org.android.go.sopt.util.extension.showSnackbar
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Success
Expand Down Expand Up @@ -51,8 +52,8 @@ class FollowerFragment : BindingFragment<FragmentFollowerBinding>(R.layout.fragm
viewModel.getFollowerListState.observe(viewLifecycleOwner) { state ->
when (state) {
is Success -> followerAdapter?.submitList(viewModel.followerList)
is Failure -> {}
is Error -> {}
is Failure -> requireContext().showSnackbar(binding.root, getString(R.string.follower_get_follower_list_null_msg))
is Error -> requireContext().showSnackbar(binding.root, getString(R.string.unknown_error_msg))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.android.go.sopt.domain.model.Follower
import org.android.go.sopt.domain.repository.FollowerRepository
import org.android.go.sopt.util.state.RemoteUiState
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Success
import retrofit2.HttpException
import timber.log.Timber
Expand All @@ -36,14 +37,17 @@ class FollowerViewModel @Inject constructor(
viewModelScope.launch {
followerRepository.getFollowerList(1)
.onSuccess { response ->
// TODO: followerList null 처리
if (response.isEmpty()) {
_getFollowerListState.value = Failure(null)
return@onSuccess
}

_followerList.value = response
_getFollowerListState.value = Success
Timber.d("GET FOLLOWER LIST SUCCESS : $response")
}
.onFailure { t ->
if (t is HttpException) {
// TODO : failure 예외 처리
_getFollowerListState.value = Error
Timber.e("GET FOLLOWER LIST FAIL : ${t.message}")
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_follower.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:id="@+id/layout_item_follower"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="30dp">

<ImageView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

<!-- follower -->
<string name="follower_header_title">Followers</string>
<string name="follower_get_follower_list_null_msg">팔로워가 존재하지 않습니다.</string>

<!-- profile -->
<string name="profile_name">이름 : %s</string>
Expand Down

0 comments on commit 3529471

Please sign in to comment.