Spring WebClient retrieve() vs exchange()

This commit is contained in:
michaelin007 2024-04-25 04:18:21 +00:00
parent c8ef6f2fd3
commit 2f1cd9a53c
1 changed files with 1 additions and 5 deletions

View File

@ -29,7 +29,7 @@ public class RetrieveAndExchangeController {
} }
@GetMapping("/user-status/{id}") @GetMapping("/user-status/{id}")
Mono<User> retrieveOneUserAndHandleErrorBaseOnStatus(@PathVariable int id) { Mono<User> retrieveOneUserAndHandleErrorBasedOnStatus(@PathVariable int id) {
return client.get() return client.get()
.uri("/{id}", id) .uri("/{id}", id)
.retrieve() .retrieve()
@ -76,10 +76,6 @@ public class RetrieveAndExchangeController {
.exchangeToMono(res -> { .exchangeToMono(res -> {
if (res.statusCode() if (res.statusCode()
.is2xxSuccessful()) { .is2xxSuccessful()) {
logger.info("Status code: " + res.headers()
.asHttpHeaders());
logger.info("Content-type" + res.headers()
.contentType());
return res.bodyToMono(User.class); return res.bodyToMono(User.class);
} else if (res.statusCode() } else if (res.statusCode()
.is4xxClientError()) { .is4xxClientError()) {