Skip to content

Commit

Permalink
[FEAT/#114] 초대코드 입장 뷰 존재하지 않는 여행 분기처리
Browse files Browse the repository at this point in the history
  • Loading branch information
crownjoe committed Jan 15, 2024
1 parent dc61277 commit 129ecbd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi
}

is UiState.Failure -> {
toast(getString(R.string.server_error))
if (state.msg == "존재하지 않는 여행입니다.") {
toast(getString(R.string.enter_trip_invite_code_error))
} else {
toast(getString(R.string.server_error))
}
}

is UiState.Loading -> return@onEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.json.JSONObject
import retrofit2.HttpException
import java.util.regex.Pattern
import javax.inject.Inject

Expand Down Expand Up @@ -54,8 +56,19 @@ class EnterTripViewModel @Inject constructor(
EnterTripRequestModel(inviteCode.value ?: "")
).onSuccess {
_tripState.value = UiState.Success(it)
}.onFailure {
_tripState.value = UiState.Failure(it.message.orEmpty())
}.onFailure { throwable ->
if (throwable is HttpException) {
val errorResponse = throwable.response()?.errorBody()?.string()
val jsonObject = JSONObject(errorResponse)
val errorCode = jsonObject.getString("code")
val errorMessage = jsonObject.getString("message")

if (errorCode == "e4043") {
_tripState.value = UiState.Failure(errorMessage)
} else {
_tripState.value = UiState.Failure(throwable.message.orEmpty())
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<string name="enter_trip_tv_hint">친구에게 받은 초대 코드 6자리를 입력해 주세요</string>
<string name="enter_trip_tv_error">잘못된 초대코드예요.</string>
<string name="enter_trip_tv_next_button">초대코드 확인하기</string>
<string name="enter_trip_invite_code_error">존재하지 않는 여행입니다.</string>

<!--invite_finish-->
<string name="invite_finish_tv_title">초대받은 여행이 맞는지\n 확인해 주세요</string>
Expand Down

0 comments on commit 129ecbd

Please sign in to comment.