Handle empty response with retrofit and rxjava 2.x
Completable was designed for such cases. It available since RxJava 1.1.1. From the official docs:
Represents a deferred computation without any value but only indication for completion or exception. The class follows a similar event pattern as Reactive-Streams: onSubscribe (onError|onComplete)?
So just change your method's return type:
@POST("login")
Completable getToken(@Header("Authorization") String authorization,
@Header("username") String username,
@Header("password") String password);
And rewrite your subscriber, e.g.:
apiManager.getToken(auth, name, pass)
...
.subscribe(() -> {
//success
}, exception -> {
//error
});
Another solution is:
@POST("login")
Observable<Response<Void>> getToken(@Header("Authorization") String authorization,
@Header("username") String username,
@Header("password") String password);
Update: But I would rather use Completable