android – 使用rxJava2和改造的UndeliverableException

有一个例外,我的应用程序反复出现在Crashlytics(Fabric)上.我使用rxjava2进行改造以进行我的http调用.

这就是崩解剂日志中的所有内容(下图).将不胜感激任何帮助/见解.

Fatal Exception: io.reactivex.exceptions.UndeliverableException: retrofit2.adapter.rxjava2.HttpException: HTTP 404 
   at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:349)
   at io.reactivex.internal.operators.single.SingleZipArray$ZipCoordinator.innerError(SingleZipArray.java:141)
   at io.reactivex.internal.operators.single.SingleZipArray$ZipSingleObserver.onError(SingleZipArray.java:177)
   at io.reactivex.internal.operators.single.SingleDoOnError$DoOnError.onError(SingleDoOnError.java:63)
   at io.reactivex.internal.operators.single.SingleDoOnSuccess$DoOnSuccess.onError(SingleDoOnSuccess.java:64)
   at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.onError(SingleSubscribeOn.java:73)
   at io.reactivex.internal.operators.observable.ObservableSingleSingle$SingleElementObserver.onError(ObservableSingleSingle.java:95)
   at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:56)
   at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37)
   at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:43)
   at io.reactivex.Observable.subscribe(Observable.java:10842)
   at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
   at io.reactivex.Observable.subscribe(Observable.java:10842)
   at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
   at io.reactivex.Single.subscribe(Single.java:2703)
   at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
   at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
   at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
   at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:818)
Caused by retrofit2.adapter.rxjava2.HttpException: HTTP 404 
   at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:54)
   at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37)
   at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:43)
   at io.reactivex.Observable.subscribe(Observable.java:10842)
   at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
   at io.reactivex.Observable.subscribe(Observable.java:10842)
   at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
   at io.reactivex.Single.subscribe(Single.java:2703)
   at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
   at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
   at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
   at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:818)

解决方法:

如果您没有给订户或Observer抛出lambable .. Rxjava无法捕获这些异常.因此,简单的解决方案是,只要订阅Observable或其他Rxjava类型,就会覆盖onError()方法并根据情况处理它们.

compositeDisposable.add(Observable.just("start")
        .doOnNext(ignored -> loadingIndicator.onNext(true))
        .flatMap(ignored -> repository.getAndroidDev())
        .subscribe(posts::onNext, throwable -> Timber.e(throwable))); //second lambda is the solution, at lease you can log the errors, if you're not willing to handle them
上一篇:java – 如何在改造中发送byte []数组


下一篇:java – 构建请求时出现Android Retrofit错误