1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-29 13:38:43 +00:00

fix of exceptions catching

This commit is contained in:
InsanusMokrassar 2019-12-13 23:54:02 +06:00
parent 1659f6f909
commit ac915b79f7
2 changed files with 27 additions and 14 deletions

View File

@ -25,6 +25,7 @@
### 0.20.2 ### 0.20.2
* New exception type `MessageIsNotModifierException` was added * New exception type `MessageIsNotModifierException` was added
* Now exceptions in requests will be caught correctly
## 0.19.0 ImplicitReflection removing ## 0.19.0 ImplicitReflection removing

View File

@ -13,6 +13,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.call.HttpClientCall import io.ktor.client.call.HttpClientCall
import io.ktor.client.call.receive import io.ktor.client.call.receive
import io.ktor.client.features.ClientRequestException
import io.ktor.client.response.readText
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
@ -48,6 +50,7 @@ class KtorRequestsExecutor(
if (call == null) { if (call == null) {
throw IllegalArgumentException("Can't execute request: $request") throw IllegalArgumentException("Can't execute request: $request")
} }
try {
val content = call.response.receive<String>() val content = call.response.receive<String>()
val responseObject = jsonFormatter.parse(Response.serializer(), content) val responseObject = jsonFormatter.parse(Response.serializer(), content)
@ -68,6 +71,15 @@ class KtorRequestsExecutor(
"Can't get result object from $content" "Can't get result object from $content"
) )
}) })
} catch (e: ClientRequestException) {
val content = e.response.readText()
val responseObject = jsonFormatter.parse(Response.serializer(), content)
throw newRequestException(
responseObject,
content,
"Can't get result object from $content"
)
}
} }
} }