diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d47cd227..3716e7345c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ * All `setWebhook` extensions was marked as deprecated, renamed and replaced into `TelegramBotAPI-extensions-utils` * Typealias `ExceptionHandler` was added - it will be used for `handleSafely` * `SetWebhook` factories signatures was changed (backward compatibility was not broken) + * `executeUnsafe` now working differently * `TelegramBotAPI-extensions-api`: * Long Polling extensions now are deprecated in this project. It was replaced into `TelegramBotAPI-extensions-utils` * `TelegramBotAPI-extensions-utils`: diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt index ebb3f462ae..0dc1f6f868 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Executes.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.types.Response +import com.github.insanusmokrassar.TelegramBotAPI.utils.handleSafely import kotlinx.coroutines.* @@ -37,12 +38,15 @@ suspend fun RequestsExecutor.executeUnsafe( ): T? { var leftRetries = retries do { - try { - return execute(request) - } catch (e: RequestException) { - leftRetries-- - delay(retriesDelay) - } + handleSafely( + { + leftRetries-- + delay(retriesDelay) + null + } + ) { + execute(request) + } ?.let { return it } } while(leftRetries >= 0) return null }