Reputation: 2353
I'm calling a url with Retrofit, and I don't care about the result. Is there anyway to ignore the onNext method?
Currently I'm using:
getRetrofit().create(UserAPI.class)
.doSomething(a, b)
.subscribeOn(Schedulers.newThread())
.subscribe(t -> {}, Handler::handlerError);
As you can see, t -> {}
do nothing, and I want to reduce it like:
getRetrofit().create(UserAPI.class)
.doSomething(a, b)
.subscribeOn(Schedulers.newThread())
.subscribe(null, Handler::handlerError);
but get the error
java.lang.IllegalArgumentException: onNext can not be null
Upvotes: 2
Views: 796
Reputation: 882
I don't think there is a way to avoid the onNext()
implementation when subscribing to an observable if you want to have error handling as well. Alternatively you can create an Observer
and reuse it in your subscribe
calls, but you still need to implement the onNext()
behaviour.
Example:
Observer errorObserver = Observers.create(t -> {}, Handler::handleError);
getRetrofit().create(UserAPI.class)
.doSomething(a, b)
.subscribeOn(Schedulers.newThread())
.subscribe(errorObserver);
Upvotes: 0
Reputation: 3771
Instead of Observable
you can return Completable from your Retrofit
interface. It serves exactly same purpose you need.
Upvotes: 4