Skip to content

Instantly share code, notes, and snippets.

@centralhardware
Created October 6, 2024 21:08
Show Gist options
  • Save centralhardware/403c189570bd9d6dad8963ba52dd6f80 to your computer and use it in GitHub Desktop.
Save centralhardware/403c189570bd9d6dad8963ba52dd6f80 to your computer and use it in GitHub Desktop.
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