Skip to content

Commit

Permalink
updated setUpUncaughtErrorHandlerForOnlineLibrary to handle RxJavaPlu…
Browse files Browse the repository at this point in the history
…gins errors
  • Loading branch information
CalebKL committed Jul 24, 2024
1 parent 575f078 commit ee365c6
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.annotation.VisibleForTesting
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import io.reactivex.Flowable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.exceptions.UndeliverableException
Expand Down Expand Up @@ -77,6 +78,7 @@ import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem.BookItem
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem.DividerItem
import org.kiwix.kiwixmobile.zimManager.libraryView.adapter.LibraryListItem.LibraryDownloadItem
import java.io.IOException
import java.util.LinkedList
import java.util.Locale
import java.util.concurrent.TimeUnit.MILLISECONDS
Expand Down Expand Up @@ -295,7 +297,13 @@ class ZimManageViewModel @Inject constructor(
Function6(::combineLibrarySources)
)
.doOnNext { libraryListIsRefreshing.postValue(false) }
.doOnError { throwable ->
if (throwable is OutOfMemoryError) {
Log.e("ZimManageViewModel", "Error----${throwable.printStackTrace()}")
}
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
libraryItems::postValue,
Throwable::printStackTrace
Expand Down Expand Up @@ -524,6 +532,12 @@ class ZimManageViewModel @Inject constructor(
library: PublishProcessor<LibraryNetworkEntity>
) {
RxJavaPlugins.setErrorHandler { exception ->
if (exception is RuntimeException && exception.cause == IOException()) {
Log.i(
TAG_RX_JAVA_DEFAULT_ERROR_HANDLER,
"Caught undeliverable exception: ${exception.cause}"
)
}
when (exception) {
is UndeliverableException -> {
library.onNext(
Expand Down

0 comments on commit ee365c6

Please sign in to comment.