diff --git a/data/src/main/java/com/nexters/boolti/data/repository/GiftRepositoryImpl.kt b/data/src/main/java/com/nexters/boolti/data/repository/GiftRepositoryImpl.kt index 99f5ba32..40bf9a98 100644 --- a/data/src/main/java/com/nexters/boolti/data/repository/GiftRepositoryImpl.kt +++ b/data/src/main/java/com/nexters/boolti/data/repository/GiftRepositoryImpl.kt @@ -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 @@ -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 = flow { emit(dataSource.receiveGift(GiftReceiveRequest(giftUuid))) @@ -38,10 +41,17 @@ internal class GiftRepositoryImpl @Inject constructor( } override fun getGiftPaymentInfo(giftId: String): Flow = 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 = flow { emit(dataSource.cancelGift(giftUuid)) } -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/showdetail/ShowDetailViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/showdetail/ShowDetailViewModel.kt index 0cb6cab4..19facf65 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/showdetail/ShowDetailViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/showdetail/ShowDetailViewModel.kt @@ -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 @@ -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"]) @@ -51,8 +54,8 @@ class ShowDetailViewModel @Inject constructor( _uiState.update { it.copy(showDetail = newShowDetail) } } .onFailure { - it.printStackTrace() - // todo : 예외 처리 + Firebase.crashlytics.recordException(it) + Timber.e(it) } } } @@ -60,4 +63,4 @@ class ShowDetailViewModel @Inject constructor( fun preventEvents() { _events.cancel() } -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/ticketing/SalesTicketViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/ticketing/SalesTicketViewModel.kt index 55f0f60e..641ef3c4 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/ticketing/SalesTicketViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/ticketing/SalesTicketViewModel.kt @@ -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 @@ -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 가 전달되지 않았습니다." @@ -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) }