1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

wrap client request exception into exception handling

This commit is contained in:
InsanusMokrassar 2022-08-25 13:35:15 +06:00
parent 61ac9df5e3
commit b873898100

View File

@ -78,13 +78,18 @@ class KtorRequestsExecutor(
pipelineStepsHolder.onRequestException(request, e) ?.let { return@let it } pipelineStepsHolder.onRequestException(request, e) ?.let { return@let it }
if (e is ClientRequestException) { if (e is ClientRequestException) {
val content = e.response.bodyAsText() val exceptionResult = runCatchingSafely {
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content) val content = e.response.bodyAsText()
newRequestException( val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
responseObject, newRequestException(
content, responseObject,
"Can't get result object from $content" content,
) "Can't get result object from $content"
)
}
exceptionResult.exceptionOrNull() ?.let {
CommonBotException(cause = e)
} ?: exceptionResult.getOrThrow()
} else { } else {
CommonBotException(cause = e) CommonBotException(cause = e)
} }