ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.86k stars 1.04k forks source link

StatusPages doesn't catch FreeMarker exceptions #1941

Closed Masterzach32 closed 2 years ago

Masterzach32 commented 4 years ago

Ktor Version and Engine Used (client or server and name) 1.3.2, Netty server, FreeMarker and StatusPages

Describe the bug If an exception is thrown while generating a html page using FreeMarker (ie. FreeMarker throws a TemplateException), the StatusPages feature does not consume it. I've tried catching Throwable and TemplateException:

exception<TemplateException> {
    Rollbar.error("Error generating page: ", it)
    call.respond(FreeMarkerContent(
        "error.ftl",
        mapOf("data" to ErrorData(
            500,
            "Oops! An error occurred while we were generating that page!",
            "Hit the back button on your browser and try again."
        ))
    ))
}

exception<Throwable> {
    Rollbar.error(null, it)
    call.respond(FreeMarkerContent(
        "error.ftl",
        mapOf("data" to ErrorData(
            500,
            "Oops! Something went wrong on our end!",
            it.localizedMessage
        ))
    ))
}
oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Stexxe commented 3 years ago

@Masterzach32 I can catch TemplateNotFoundException and ParseException with StatusPages on Ktor 1.6.0. Please tell me how exactly do you trigger TemplateException?