I'm new to RxJava. I have a code like this. I'm creating an observable from a string returned from repository.getStatus(). if it is null , I have to proceed with the proceed method without doing anything. If it is not null , I have to call repository.init() and then proceed. Here's what I have done.
Flowable.just(repository.getStatus()) // getStatus return a string , which can be null
.doOnError(throwable -> proceed())
.flatMapCompletable(s -> repository.init())
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
proceed();
}
@Override
public void onError(@NonNull Throwable e) {
handleErrors(t));
}
});
private void proceed(){
//
}
In case repository.getStatus() is null , wont it call the doOnError(throwable -> proceed())?
Now it is crashing when repository.getStatus() is null. What is the best Rx way to deal with this kind of a usecase?
Optional.ofNullablerequired API 24 above. My min version is 19