mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 15:19:30 +00:00
fix of cancellation exception throwing?
This commit is contained in:
@@ -30491,6 +30491,11 @@ public final class dev/inmo/tgbotapi/utils/ByteReadChannelAllocatorDeserializati
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/utils/CausedByCancellationKt {
|
||||
public static final fun causedCancellationException (Ljava/lang/Throwable;)Ljava/util/concurrent/CancellationException;
|
||||
public static final fun isCausedByCancellation (Ljava/lang/Throwable;)Z
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/utils/DefaultKSLogKt {
|
||||
public static final fun SetDefaultKTgBotAPIKSLog (ZLkotlin/jvm/functions/Function1;)V
|
||||
public static synthetic fun SetDefaultKTgBotAPIKSLog$default (ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.bot.ktor.base
|
||||
|
||||
import dev.inmo.kslog.common.*
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
||||
import dev.inmo.tgbotapi.bot.exceptions.BotException
|
||||
import dev.inmo.tgbotapi.bot.exceptions.CommonBotException
|
||||
@@ -16,6 +17,7 @@ import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.statement.*
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class DefaultKtorRequestsExecutor internal constructor(
|
||||
@@ -47,7 +49,7 @@ class DefaultKtorRequestsExecutor internal constructor(
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return runCatching {
|
||||
return runCatchingLogging(logger = logger) {
|
||||
logger.v { "Start request $request" }
|
||||
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
||||
requestsLimiter.limit(request) {
|
||||
@@ -95,6 +97,7 @@ class DefaultKtorRequestsExecutor internal constructor(
|
||||
CommonBotException(cause = e)
|
||||
} ?: exceptionResult.getOrThrow()
|
||||
}
|
||||
is CancellationException,
|
||||
is BotException -> e
|
||||
else -> CommonBotException(cause = e)
|
||||
}.also { newException ->
|
||||
|
@@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import kotlinx.coroutines.CancellationException
|
||||
|
||||
fun Throwable.causedCancellationException(): CancellationException? {
|
||||
var current = this
|
||||
while (current !is CancellationException) {
|
||||
when {
|
||||
// It is possible, that API will be changed and cancellation will be caused by something else
|
||||
current is CancellationException && current.cause == null -> return current
|
||||
else -> current = current.cause ?: return null
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() == null
|
@@ -19,7 +19,7 @@ private inline fun CreateDefaultKSLogger(
|
||||
): KSLog {
|
||||
val filter: MessageFilter? = if (dropCancellationExceptions) {
|
||||
{ ll, message, e ->
|
||||
e !is CancellationException
|
||||
e ?.isCausedByCancellation() != true
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
Reference in New Issue
Block a user