I am doing something like this: in my Fragment, I am observing a LiveData exposed by a ViewModel that encapsulates different UI states like error, loading, success state, etc. Within the said ViewModel, I start an RxJava2 stream that kicks off a chain of REST API requests via Retrofit:
public LiveData<UIState> doSomething() {
compositeDisposable.add(somethingRepo.doA()
.andThen(somethingRepo.doB())
.andThen(somethingRepo.doC())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(disposable -> status.setValue(UIState.LOADING()))
.subscribe(() -> status.setValue(UIState.SUCCESS()), error -> {
Log.d("SettingsVM", "error: " + error.getClass().getSimpleName());
if(error instanceof VersionAlreadyExistsException) {
status.setValue(UIState.VERSION_EXISTS());
} else {
status.setValue(UIState.ERROR(error.getMessage()));
}
})
);
return status;
}
However, according to my custom logger that implements HttpLoggingInterceptor.Logger, I am getting a java.net.SocketException: Socket closed during somethingRepo.doA(), but it seems that I am not getting the Exception in doSomething()'s onError. Here is the full somethingRepo.doA():
public Completable doA() {
return api.doRequest(paramRepository.getUrl(false),
paramRepository.getAuthorization(),
paramRepository.getName())
.flatMapCompletable(requestResponse-> {
if(paramRepository.getVersion().contentEquals(requestResponse.getVersion())) {
return Completable.error(new VersionAlreadyExistsException());
} else {
return Completable.complete();
}
});
}
api.doRequest is a GET request that looks like this:
@GET
Single<RequestResponse> doRequest (
@Url String url,
@Header("authorization") String authorization,
@Query("merch") String name);
Interestingly, on another Android app, I sent a POST to the same URL I am using in the previous example and what I got was HTTP FAILED: java.net.ConnectException: Failed to connect to /180.232.98.122:7443.
I am aware of a similar issue being opened in the official Retrofit repo and a similar SO question here, but those two are unresolved, thus I would like to hear if anyone here has encountered the same behavior.