Reputation: 127
public Flux<Entity> getRatesFlux(String hash, String apiUrl) {
// url is a restfull parameters in path
return RatesReactiveRepository
.findAll()
.flatMap(rate -> {
log.info("{} rate read from MongoDb: {}", logHash, rate);
String url = apiUrl + "/" + rate.getRateName();
log.debug("{}, START {} URI: {}",
logHash,
"productsController.ratesServiceImpl.getratesFlux",
url);
// Create HttpHeaders object and set multiple headers
HttpHeaders headers = new HttpHeaders();
headers.add("hash", hash);
return webClient
.post()
.uri(url)
.headers(
httpHeaders -> {
httpHeaders.set("hash", hash);
}
)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Entity.class);
});
I need to capture body and status code for any body of Mono<ClientResponse>
in case of 200 OK Http Status Code and return complete ClientResponse.
In case of Status code 5xx 2xx return Status code with an error message.
If I use .onStatus
I can't return object to return from this api in case of some in success and others in error.
I need to return a Flux as API with:
I try to use zipWith without success.
How can it be done?
Upvotes: 0
Views: 21