[3.3.2]
[抽出启动自驾、代码整理]
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
package com.mogo.och.common.module.utils
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.exceptions.UndeliverableException
|
||||
import io.reactivex.plugins.RxJavaPlugins
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import io.reactivex.functions.Consumer
|
||||
|
||||
object RxUtils {
|
||||
|
||||
private const val TAG = "RxUtils"
|
||||
fun disposeSubscribe(subscribe: Disposable?) {
|
||||
subscribe?.let {
|
||||
if (!it.isDisposed) {
|
||||
@@ -29,4 +37,41 @@ object RxUtils {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃
|
||||
// The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the excTeption has nowhere to go to begin with
|
||||
fun errCatch(){
|
||||
RxJavaPlugins.setErrorHandler(Consumer { e ->
|
||||
if (e is UndeliverableException) {
|
||||
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "UndeliverableException")
|
||||
return@Consumer
|
||||
}
|
||||
if (e is IOException) { //
|
||||
// fine, irrelevant network problem or API that throws on cancellation
|
||||
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "IOException")
|
||||
return@Consumer
|
||||
}
|
||||
if (e is InterruptedException) {
|
||||
// fine, some blocking code was interrupted by a dispose call
|
||||
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "InterruptedException")
|
||||
return@Consumer
|
||||
}
|
||||
if (e is NullPointerException || e is IllegalArgumentException) {
|
||||
// that's likely a bug in the application
|
||||
CallerLogger.d(
|
||||
SceneConstant.M_OCHCOMMON + TAG,
|
||||
"NullPointerException or IllegalArgumentException"
|
||||
)
|
||||
Thread.currentThread().uncaughtExceptionHandler?.uncaughtException(Thread.currentThread(), e)
|
||||
return@Consumer
|
||||
}
|
||||
if (e is IllegalStateException) {
|
||||
// that's a bug in RxJava or in a custom operator
|
||||
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "IllegalStateException")
|
||||
Thread.currentThread().uncaughtExceptionHandler?.uncaughtException(Thread.currentThread(), e)
|
||||
return@Consumer
|
||||
}
|
||||
CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG, "Undeliverable exception")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user