When I subscribe to a Rx Observable and forget to ...
# announcements
d
When I subscribe to a Rx Observable and forget to handle the onError call my app crashs. To prevent this I try to write a Observable extension. It works so far but it has a little flaw 😞
Copy code
fun <T> Observable<T>.subscribeOrLogError(onNext: Action1<T>): Subscription {

    return subscribe(object : Subscriber<T>() {

        override fun onCompleted() {
            // do nothing
        }

        override fun onError(e: Throwable) {
            Timber.e(e, "")
        }

        override fun onNext(args: T) {
            onNext.call(args)
        }
    })
}
When I use it I have to write:
Copy code
val subject = PublishSubject<Boolean>()
subject.subscribeOrLogError(Action1<Boolean> { it -> Timber.i("value: " + it) })
Is there a way that I don’t need to write
Action1<Boolean>
in the subject.subscribeOrLogError call?