Observer.onError firing off inconsistently

前端 未结 2 999

I am using Retrofit to access my API as follows:

public interface UserService {
    ...
    @POST(\"/user/login\")
    public Observable register(@Bo         


        
相关标签:
2条回答
  • 2021-02-14 10:06

    you can use unsafe unsafeSubscribe.

    ...
    .subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    .unsafeSubscribe(new Observer<User>() {
        @Override
        public void onCompleted() {
        ....
        }
    
        @Override
        public void onError(Throwable e) {
        ....
        }
    
        @Override
        public void onNext(User user) {
        ....
        }
    });
    ...
    
    0 讨论(0)
  • 2021-02-14 10:08

    In my previous experience with RxJava the OnErrorFailedException means that an exception occurred while handling another exception in the onError method.

    If you don't see stack trace of the real cause it's probably due the bug in RxJava with CompositeException (versions 0.19.2 and above) https://github.com/Netflix/RxJava/issues/1405

    As a workaround try to wrap your onError code within try-catch block and log the exception. This way you will see what's the problem with your onError implementation and you will be able to solve the problem.

    @Override
    public void onError(Throwable e) {
       try {
          ...
       catch(Throwable e) {
          // Log the exception
       }
    }
    
    0 讨论(0)
提交回复
热议问题