diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt index eba7e7d4a1..3532ec5217 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/DownloadFileChannelRequestCallFactory.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.bot.Ktor.base +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.requests.DownloadFileStream import dev.inmo.tgbotapi.requests.abstracts.Request @@ -26,10 +27,10 @@ object DownloadFileChannelRequestCallFactory : KtorCallFactory { ByteReadChannelAllocator { val scope = CoroutineScope(coroutineContext) val outChannel = ByteChannel() - scope.launch { + scope.launchSafelyWithoutExceptions { client.get(fullUrl).execute { httpResponse -> val channel: ByteReadChannel = httpResponse.receive() - channel.copyTo(outChannel) + channel.copyAndClose(outChannel) } } outChannel