commit 3c6e545856d38c2dc89d49d31d0b63e10778a7fe parent f64a66426059522874d46f6fa0aa4f4b04001688 Author: Wim Dupont <wim@wimdupont.com> Date: Tue, 17 Jan 2023 21:29:58 +0100 api timeout and error handling Former-commit-id: dbd938d9f99211c92029f2af50a14363c3a8a3f1 Diffstat:
M | src/main/java/com/wimdupont/personalweb/api/AffirmationApi.java | | | 6 | +++++- |
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/wimdupont/personalweb/api/AffirmationApi.java b/src/main/java/com/wimdupont/personalweb/api/AffirmationApi.java @@ -6,6 +6,8 @@ import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; +import java.time.Duration; + @Component @RequiredArgsConstructor public class AffirmationApi { @@ -18,7 +20,9 @@ public class AffirmationApi { return webClient.get() .uri(AFFIRMATION_URL) .retrieve() - .bodyToMono(Affirmation.class); + .bodyToMono(Affirmation.class) + .timeout(Duration.ofSeconds(3)) + .onErrorReturn(new Affirmation("You're the best!")); } }