Browse Source

Swallow observable errors instead of crashing

arkon 3 năm trước cách đây
mục cha
commit
abfdde28ef

+ 4 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/BasePresenter.kt

@@ -45,7 +45,7 @@ open class BasePresenter<V> : RxPresenter<V>() {
      * @param onNext function to execute when the observable emits an item.
      * @param onError function to execute when the observable throws an error.
      */
-    fun <T> Observable<T>.subscribeFirst(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) = compose(deliverFirst<T>()).subscribe(split(onNext, onError)).apply { add(this) }
+    fun <T> Observable<T>.subscribeFirst(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit) = { _, _ -> }) = compose(deliverFirst<T>()).subscribe(split(onNext, onError)).apply { add(this) }
 
     /**
      * Subscribes an observable with [deliverLatestCache] and adds it to the presenter's lifecycle
@@ -54,7 +54,7 @@ open class BasePresenter<V> : RxPresenter<V>() {
      * @param onNext function to execute when the observable emits an item.
      * @param onError function to execute when the observable throws an error.
      */
-    fun <T> Observable<T>.subscribeLatestCache(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) = compose(deliverLatestCache<T>()).subscribe(split(onNext, onError)).apply { add(this) }
+    fun <T> Observable<T>.subscribeLatestCache(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit) = { _, _ -> }) = compose(deliverLatestCache<T>()).subscribe(split(onNext, onError)).apply { add(this) }
 
     /**
      * Subscribes an observable with [deliverReplay] and adds it to the presenter's lifecycle
@@ -63,7 +63,7 @@ open class BasePresenter<V> : RxPresenter<V>() {
      * @param onNext function to execute when the observable emits an item.
      * @param onError function to execute when the observable throws an error.
      */
-    fun <T> Observable<T>.subscribeReplay(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) = compose(deliverReplay<T>()).subscribe(split(onNext, onError)).apply { add(this) }
+    fun <T> Observable<T>.subscribeReplay(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit) = { _, _ -> }) = compose(deliverReplay<T>()).subscribe(split(onNext, onError)).apply { add(this) }
 
     /**
      * Subscribes an observable with [DeliverWithView] and adds it to the presenter's lifecycle
@@ -72,7 +72,7 @@ open class BasePresenter<V> : RxPresenter<V>() {
      * @param onNext function to execute when the observable emits an item.
      * @param onError function to execute when the observable throws an error.
      */
-    fun <T> Observable<T>.subscribeWithView(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) = compose(DeliverWithView<V, T>(view())).subscribe(split(onNext, onError)).apply { add(this) }
+    fun <T> Observable<T>.subscribeWithView(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit) = { _, _ -> }) = compose(DeliverWithView<V, T>(view())).subscribe(split(onNext, onError)).apply { add(this) }
 
     /**
      * A deliverable that only emits to the view if attached, otherwise the event is ignored.