diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt index 789ca33c49..eb8b2f2679 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt @@ -36,16 +36,13 @@ suspend fun RequestsExecutor.executeUnsafe( retriesDelay: Long = 1000L ): T? { var leftRetries = retries - while(true) { + do { try { return execute(request) } catch (e: RequestException) { - if (leftRetries > 0) { - leftRetries-- - delay(retriesDelay) - } else { - return null - } + leftRetries-- + delay(retriesDelay) } - } + } while(leftRetries >= 0) + return null }