Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 295 로그인 예외처리 수정 #297

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
@@ -1,7 +1,9 @@
package com.example.mhnfe.ui.screens.auth.login

import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import android.widget.Toast
import androidx.datastore.core.DataStore
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -14,6 +16,7 @@ import com.example.mhnfe.data.remote.response.RefreshToken
import com.example.mhnfe.data.remote.response.SendPasswordResponse
import com.example.mhnfe.data.repository.AuthRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
Expand All @@ -30,7 +33,8 @@ class LoginViewModel @Inject constructor(
private val refreshTokenDataStore: DataStore<RefreshToken>,
private val groupIdDataStore: DataStore<GroupId>,
private val memberIdDataStore: DataStore<MemberId>,
private val sharedPreferences: SharedPreferences
private val sharedPreferences: SharedPreferences,
@ApplicationContext private val context: Context
) : ViewModel() {

// 로그인 결과 상태
Expand Down Expand Up @@ -98,11 +102,16 @@ class LoginViewModel @Inject constructor(
_errorMessage.value = "네트워크 오류가 발생했습니다. 인터넷 연결을 확인해주세요."
} catch (e: HttpException) {
when (e.code()) {
400, 404 -> {
400 -> {
_errorMessage.value = "잘못된 아이디 또는 비밀번호입니다."
Log.e("LoginViewModel", "Error: ${_errorMessage.value}")
}

404 -> {
_errorMessage.value = "회원 정보를 찾을 수 없습니다."
Log.e("LoginViewModel", "Error: ${_errorMessage.value}")
}

else -> {
Log.e("LoginViewModel", "HttpException: ${e.message}")
_errorMessage.value = "서버 오류가 발생했습니다. 다시 시도해주세요."
Expand Down Expand Up @@ -182,6 +191,7 @@ class LoginViewModel @Inject constructor(
if(response.result.code == 200) {
_sendPasswordResponse.value = response
_errorMessage.value = null
Toast.makeText(context, "임시 비밀번호가 메일로 전송되었습니다.", Toast.LENGTH_SHORT).show()
} else {
_errorMessage.value = mapErrorMessage(
response.result.code,
Expand Down
Loading