CLOVIS
06/08/2026, 1:57 PMCLOVIS
06/08/2026, 1:58 PMYoussef Shoaib [MOD]
06/08/2026, 2:03 PMYoussef Shoaib [MOD]
06/08/2026, 2:04 PMsimon.vergauwen
06/08/2026, 2:05 PMYoussef Shoaib [MOD]
06/08/2026, 2:06 PMCLOVIS
06/08/2026, 2:07 PMraise inside a Ktor server endpoint, which translates the call to a HTTP responseCLOVIS
06/08/2026, 2:07 PMsimon.vergauwen
06/08/2026, 2:08 PMCLOVIS
06/08/2026, 2:11 PMCLOVIS
06/08/2026, 2:11 PMphldavies
06/08/2026, 3:11 PMarrow-raise-ktor-server module currently provides, albeit the ApplicationCall.respondOrRaise function will respond with the result of the lambda if nothing is raised, but otherwise allows you to raise(Response) (similar to your raise(HttpFailure) ) to shortcircuit the handler.CLOVIS
06/08/2026, 3:12 PMCLOVIS
06/08/2026, 3:12 PMphldavies
06/08/2026, 3:14 PMrouting {
get("/ping") {
raise {
val value = call.parameters["value"]
ensureNotNull(value) { HttpFailure("Missing value", HttpStatusCode.UnprocessableEntity) }
call.respond("Pong: $value")
}
}
}
you can do
routing {
get("/ping") {
call.respondOrRaise {
val value = call.parameters["value"]
ensureNotNull(value) { Response(UnprocessableEntity, "Missing value") }
"Pong: $value"
}
}
}phldavies
06/08/2026, 3:16 PMensureNotNull(value) { UnprocessableEntity("Missing value") } )CLOVIS
06/08/2026, 3:18 PMphldavies
06/08/2026, 3:18 PMgetOrRaise("/ping") { ... } equivalent of get("/ping") { call.respondOrRaise { ... } }