1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-15 05:09:30 +00:00

Merge pull request #1003 from InsanusMokrassar/28.0.2

28.0.2
This commit is contained in:
2025-09-10 15:59:20 +06:00
committed by GitHub
5 changed files with 28 additions and 4 deletions

View File

@@ -1,5 +1,11 @@
# TelegramBotAPI changelog
## 28.0.2
* `Core`:
* [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) - `[Bug] Invalid detection of isCausedByCancellation()`
* [#1002](https://github.com/InsanusMokrassar/ktgbotapi/issues/1002) - `Unable to handle UnauthorizedException with buildBehaviourWithLongPolling`
## 28.0.1
* `Version`:

View File

@@ -9,4 +9,4 @@ kotlin.incremental.js=true
ksp.useKSP2=false
library_group=dev.inmo
library_version=28.0.1
library_version=28.0.2

View File

@@ -87,6 +87,7 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling(
timeoutSeconds = timeoutSeconds,
autoDisableWebhooks = autoDisableWebhooks,
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis,
exceptionsHandler = defaultExceptionsHandler
)
}

View File

@@ -84,7 +84,7 @@ class DefaultKtorRequestsExecutor internal constructor(
when (e) {
is ClientRequestException -> {
val exceptionResult = runCatching {
val exceptionResult = runCatchingLogging(logger = Log) {
val content = e.response.bodyAsText()
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
newRequestException(

View File

@@ -2,6 +2,17 @@ package dev.inmo.tgbotapi.utils
import kotlinx.coroutines.CancellationException
/**
* Traverses this throwable's cause chain to find a [CancellationException].
*
* It walks through `this` and its `cause`s until the first [CancellationException] is encountered,
* and returns that exception. If no [CancellationException] is found in the chain, returns `null`.
*
* This is useful when you need to distinguish cancellations from other failures while handling errors.
*
* @receiver the root [Throwable] to inspect
* @return the first [CancellationException] found in the cause chain, or `null` if none present
*/
fun Throwable.causedCancellationException(): CancellationException? {
var current = this
while (current !is CancellationException) {
@@ -15,4 +26,10 @@ fun Throwable.causedCancellationException(): CancellationException? {
return current
}
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() == null
/**
* Checks whether this throwable (or any of its causes) is a [CancellationException].
*
* @receiver the [Throwable] to inspect
* @return `true` if a [CancellationException] is found in the cause chain, `false` otherwise
*/
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() != null