From 79bfd5d95c7a6a6fffcba26079f11f781f8637a8 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Wed, 19 Jan 2022 23:53:02 +0100 Subject: [PATCH] Don't print stacktrace if the bot is not found --- .../it/tdlight/reactiveapi/PeriodicRestarter.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/tdlight/reactiveapi/PeriodicRestarter.java b/src/main/java/it/tdlight/reactiveapi/PeriodicRestarter.java index 882cf08..4b465e4 100644 --- a/src/main/java/it/tdlight/reactiveapi/PeriodicRestarter.java +++ b/src/main/java/it/tdlight/reactiveapi/PeriodicRestarter.java @@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; import reactor.core.Disposable; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; +import reactor.util.retry.Retry; public class PeriodicRestarter { @@ -140,8 +141,14 @@ public class PeriodicRestarter { multiClient .request(userId, liveId, new Close(), Instant.now().plus(Duration.ofSeconds(15))) .subscribeOn(Schedulers.parallel()) - .retry(5) - .doOnError(ex -> LOG.error("Failed to restart bot {} (liveId={})", userId, liveId, ex)) + .retryWhen(Retry.backoff(5, Duration.ofSeconds(1)).maxBackoff(Duration.ofSeconds(5))) + .doOnError(ex -> { + if (ex instanceof TdError tdError && tdError.getTdCode() == 404) { + LOG.warn("Failed to restart bot {} (liveId={}): not found", userId, liveId); + } else { + LOG.error("Failed to restart bot {} (liveId={})", userId, liveId, ex); + } + }) .onErrorResume(ex -> Mono.empty()) .subscribe(); }