So I have my form
model which holds all data I want to validate and then send to the server. Let's keep it as simple as possible - isFormValid
or api request should return Observable.errr(throwable)
which should call onError()
in the subscriber
.
public void submitForm(Form form){
Observable
.just(form)
.flatMap(form->{
if(isFormValid(form))
return Observable.just(form);
else
return Observable.error(someValidationError);
})
.flatMap(form->{
Request req = new Request(form);
try{
return Observable.just(getResponseFrom(req));
}
catch(ApiException e){
return Observable.error(e)
}
}).subscribe(
new Subscriber<ResponseModel>(){
@Override
public void onComplete(){}
@Override
public void onError(Throwable t){}
@Override
public void onNext(ResponseModel model){}
}
);
}
Ok, now let's say user enters invalid data, submitForm()
is called and -sure enought- onError
is called in subscriber
and then onComplete
. The user then enters valid data and submitForm()
is called again.
Now here's the problem - in the second submitForm()
call nothing happens! At least flatMap
Func1
and the second flatMap
Func2
are not called.
Why? What am I doing wrong ? Is it an architectural flaw?