Skip to content

Commit

Permalink
Boolti-281 fix: 잠재적 크래시 방어 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mangbaam committed Aug 4, 2024
1 parent 15e60ba commit 855d816
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.boolti.data.repository

import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.nexters.boolti.data.datasource.GiftDataSource
import com.nexters.boolti.data.network.request.GiftReceiveRequest
import com.nexters.boolti.data.network.response.toDomains
Expand All @@ -12,10 +14,11 @@ import com.nexters.boolti.domain.request.FreeGiftRequest
import com.nexters.boolti.domain.request.GiftApproveRequest
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import timber.log.Timber
import javax.inject.Inject

internal class GiftRepositoryImpl @Inject constructor(
private val dataSource: GiftDataSource
private val dataSource: GiftDataSource,
) : GiftRepository {
override fun receiveGift(giftUuid: String): Flow<Boolean> = flow {
emit(dataSource.receiveGift(GiftReceiveRequest(giftUuid)))
Expand All @@ -38,10 +41,17 @@ internal class GiftRepositoryImpl @Inject constructor(
}

override fun getGiftPaymentInfo(giftId: String): Flow<ReservationDetail> = flow {
emit(dataSource.getGiftPaymentInfo(giftId).toDomain())
runCatching {
dataSource.getGiftPaymentInfo(giftId)
}.onSuccess {
emit(it.toDomain())
}.onFailure {
Firebase.crashlytics.recordException(it)
Timber.e(it)
}
}

override fun cancelGift(giftUuid: String): Flow<Boolean> = flow {
emit(dataSource.cancelGift(giftUuid))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.nexters.boolti.presentation.screen.showdetail
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.nexters.boolti.domain.repository.AuthRepository
import com.nexters.boolti.domain.repository.ShowRepository
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -16,13 +18,14 @@ import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class ShowDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val showRepository: ShowRepository,
private val authRepository: AuthRepository,
authRepository: AuthRepository,
) : ViewModel() {
private val showId: String = checkNotNull(savedStateHandle["showId"])

Expand Down Expand Up @@ -51,13 +54,13 @@ class ShowDetailViewModel @Inject constructor(
_uiState.update { it.copy(showDetail = newShowDetail) }
}
.onFailure {
it.printStackTrace()
// todo : 예외 처리
Firebase.crashlytics.recordException(it)
Timber.e(it)
}
}
}

fun preventEvents() {
_events.cancel()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.nexters.boolti.presentation.screen.ticketing

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.nexters.boolti.domain.model.TicketWithQuantity
import com.nexters.boolti.domain.repository.TicketingRepository
import com.nexters.boolti.domain.request.SalesTicketRequest
import com.nexters.boolti.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
Expand All @@ -18,7 +18,7 @@ import javax.inject.Inject
class SalesTicketViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val repository: TicketingRepository,
) : ViewModel() {
) : BaseViewModel() {

private val showId: String = requireNotNull(savedStateHandle["showId"]) {
"SalesTicketViewModel 에 showId 가 전달되지 않았습니다."
Expand All @@ -28,7 +28,7 @@ class SalesTicketViewModel @Inject constructor(
val uiState = _uiState.asStateFlow()

fun load() {
viewModelScope.launch {
viewModelScope.launch(recordExceptionHandler) {
repository.getSalesTickets(SalesTicketRequest(showId))
.firstOrNull()?.let { tickets ->
_uiState.update { it.copy(tickets = tickets) }
Expand Down

0 comments on commit 855d816

Please sign in to comment.