Skip to content

Commit

Permalink
Merge pull request #297 from IoTeaTime/fix/295-로그인-예외처리-수정
Browse files Browse the repository at this point in the history
fix: 295 로그인 예외처리 수정
  • Loading branch information
Kwahk authored Dec 11, 2024
2 parents 1a12a35 + cd4d790 commit 84bc89a
Showing 1 changed file with 12 additions and 2 deletions.
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

0 comments on commit 84bc89a

Please sign in to comment.