https://kotlinlang.org logo
#ktor
Title
# ktor
c

Claude Brisson

01/19/2022, 5:56 PM
Hi all. With 2.0-eap (2.0.0-eap-278), StatusPages does not seem to catch exceptions occurring during HTML DSL rendering. I saw a git commit fixing the same issue for freemarker, KTOR-343 ( git diff 18222b4e8~ 18222b4e8 ), which I don't fully understand, lacking some knowledge about the 2.0 refactoring; I was wondering if it was the same kind of problem. Also, would the Velocity plugin also be affected?
a

Aleksei Tirman [JB]

01/20/2022, 9:11 AM
Could you please file an issue with the attached code to reproduce this problem?
c

Claude Brisson

01/20/2022, 9:14 AM
Ok. But just to confirm, having
install<StatusPages> { cause -> call.respond(io.ktor.http.HttpStatusCode.InternalServerError) }
should be enough to respond 500 if an uncatched exception happens during rendering, right?
a

Aleksei Tirman [JB]

01/20/2022, 9:29 AM
It should be the following code using Ktor beta:
Copy code
install(StatusPages) {
    exception<Throwable> { call: ApplicationCall, _ ->
        call.respond(HttpStatusCode.InternalServerError)
    }
}
c

Claude Brisson

01/20/2022, 9:45 AM
Your code seems to only work in 2.0.0-beta-1, not in 2.0.0-eap-278 ; and alas the most recent version of ktor-html-builder on https://maven.pkg.jetbrains.space/public/p/ktor/eap/ is still eap-278
Ah, ok, understood, its name changed to ktor-server-html-builder, sorry
👍 1
The exception is catched, but ktor returns 200 with an empty document. I'll open an issue.