From f77e40eb13bd47a4f79450e9efe49afac6289fea Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 28 Feb 2024 22:39:59 +0100 Subject: [PATCH] test: HandoverIT-POC - Fixed logging of failed client-requests --- .../de/juplo/kafka/chat/backend/TestClient.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestClient.java b/src/test/java/de/juplo/kafka/chat/backend/TestClient.java index 524c297c..0d54600d 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestClient.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestClient.java @@ -6,9 +6,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; +import java.nio.charset.Charset; import java.time.Duration; import java.util.concurrent.ThreadLocalRandom; @@ -27,11 +29,16 @@ public class TestClient implements Runnable sendMessage(chatRoom, message) .retryWhen(Retry.fixedDelay(10, Duration.ofSeconds(1))) .map(MessageTo::toString) + .onErrorResume(throwable -> + { + WebClientResponseException e = (WebClientResponseException)throwable.getCause(); + return Mono.just(e.getResponseBodyAsString(Charset.defaultCharset())); + }) .subscribe(result -> log.info( - "{} sent message \"{}\" to {}", + "{} sent a message to {}: {}", user, - message, - chatRoom)); + chatRoom, + result)); } try { -- 2.20.1