Skip to content

Commit

Permalink
feat(ExploreViewModel): send exception reports to the crashlytics
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed May 21, 2024
1 parent 61f2ae9 commit 580966b
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -25,11 +26,14 @@ class ExploreViewModel : ViewModel() {
val popularsPage = mutableIntStateOf(1)
val refreshing = mutableStateOf(false)

private val crashlytics = FirebaseCrashlytics.getInstance()

fun fetchOngoings() {
viewModelScope.launch(Dispatchers.IO) {
ShikimoriRepository.fetchOngoings(1, ContentType.ANIME)
.catch {
it.printStackTrace()
crashlytics.recordException(it)
contentObservationStatus.value = ObservationStatus(Status.Failure, it as Exception)
emitAll(emptyFlow())
}.collectLatest {
Expand All @@ -44,6 +48,7 @@ class ExploreViewModel : ViewModel() {
ShikimoriRepository.fetchPopulars(1..popularsPage.intValue, ContentType.ANIME)
.catch {
it.printStackTrace()
crashlytics.recordException(it)
contentObservationStatus.value = ObservationStatus(Status.Failure, it as Exception)
emitAll(emptyFlow())
}.onCompletion {
Expand Down

0 comments on commit 580966b

Please sign in to comment.