Mono.defaultIfEmpty is called even when the object is not empty
Here is the code snippet
public Mono<ResponseEntity<Response>> validateUser(@Valid @RequestBody ValidateUserRequest request, BindingResult errors){
Mono<Response> response = null;
try
{
response = myservice.validateUser(request);
return response.map(myresponse -> {
if(null!=myresponse.getError(){
return ResponseEntity.status(HttpStatus.OK).body(myresponse);
}).defaultIfEmpty(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(transformer.tranformDefaultResponse());
}
} catch(Exception e) {
return mono.just(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(transformer.tranformExceptionResponse());
}
tranformDefaultResponse is called immediately after myservice.validateUser(request);
always even though the response is not empty. How can we prevent that from happening? I want defaultIfEmpty to be called only when the response is empty.