Created
October 6, 2024 21:08
-
-
Save centralhardware/403c189570bd9d6dad8963ba52dd6f80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.centralhardware.znatoki.telegram.statistic.telegram | |
import dev.inmo.tgbotapi.bot.ktor.KtorCallFactory | |
import dev.inmo.tgbotapi.bot.ktor.KtorPipelineStepsHolder | |
import dev.inmo.tgbotapi.requests.GetUpdates | |
import dev.inmo.tgbotapi.requests.abstracts.Request | |
import io.ktor.client.plugins.HttpRequestTimeoutException | |
class KtorPipelineStepsHolder : KtorPipelineStepsHolder { | |
companion object { | |
var health: Boolean = false; | |
} | |
override suspend fun <T : Any> onRequestException(request: Request<T>, t: Throwable): T? { | |
if (t is HttpRequestTimeoutException && | |
t.message!!.startsWith("Request timeout has expired [url=https://api.telegram.org/bot") | |
) { | |
health = true; | |
} else { | |
health = false; | |
} | |
return super.onRequestException(request, t) | |
} | |
override suspend fun <T : Any> onRequestReturnResult( | |
result: Result<T>, | |
request: Request<T>, | |
callsFactories: List<KtorCallFactory> | |
): T { | |
if (request is GetUpdates && result.isSuccess) { | |
health = true | |
} | |
return super.onRequestReturnResult(result, request, callsFactories) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment