mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
add KtorPipelineStepsHolder#onRequestReturnResult
This commit is contained in:
parent
863c872f35
commit
81ad55b19f
@ -75,7 +75,8 @@ class KtorRequestsExecutor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||||
return safely(
|
return runCatching {
|
||||||
|
safely(
|
||||||
{ e ->
|
{ e ->
|
||||||
pipelineStepsHolder.onRequestException(request, e) ?.let { return@safely it }
|
pipelineStepsHolder.onRequestException(request, e) ?.let { return@safely it }
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ class KtorRequestsExecutor(
|
|||||||
} else {
|
} else {
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
||||||
@ -116,6 +118,9 @@ class KtorRequestsExecutor(
|
|||||||
} ?: pipelineStepsHolder.onRequestResultAbsent(request, callsFactories) ?: error("Can't execute request: $request")
|
} ?: pipelineStepsHolder.onRequestResultAbsent(request, callsFactories) ?: error("Can't execute request: $request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.let {
|
||||||
|
pipelineStepsHolder.onRequestReturnResult(it, request, callsFactories)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
@ -60,4 +60,14 @@ interface KtorPipelineStepsHolder {
|
|||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
callsFactories: List<KtorCallFactory>
|
callsFactories: List<KtorCallFactory>
|
||||||
): T? = null
|
): T? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This step will be called when the [result] has been retrieved (or exception has happened). If returns value -
|
||||||
|
* that value will be returned from [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||||
|
*/
|
||||||
|
suspend fun <T: Any> onRequestReturnResult(
|
||||||
|
result: Result<T>,
|
||||||
|
request: Request<T>,
|
||||||
|
callsFactories: List<KtorCallFactory>
|
||||||
|
): T = result.getOrThrow()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user