From: Kai Moritz Date: Wed, 28 Feb 2024 21:39:59 +0000 (+0100) Subject: test: HandoverIT-POC - Fixed logging of failed client-requests X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=ae20ad5f69ef50a958bd5867e103a1aee79bbdf2;p=demos%2Fkafka%2Fchat test: HandoverIT-POC - Fixed logging of failed client-requests --- 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 {