s? It seems like they're rethrown... but in Ktor, I'd like to use it to return some kind of timeout response to the client... (I suspect that Ktor just hangs w/o some kind of timeout in certain situations...)
dave08
04/13/2023, 12:11 PM
Would this do it:
Copy code
private suspend inline fun KtorCtx.respond(
statusCode: HttpStatusCode,
noinline action: suspend Raise<ErrorContext>.() -> String
): Unit = fold(
{
withTimeout(5.seconds) {
action()
}
},
{
if (it is TimeoutCancellationException)
call.respond(RequestTimeout)
else
throw it
},
{ error ->
val jsonError = Json.encodeToString(error)
call.respond(BadRequest, error.toString())
application.log.error(jsonError)
}) { a ->
call.respondText(a, ContentType.Application.Json, statusCode)
}