When installing exception handlers via the StatusP...
# ktor
m
When installing exception handlers via the StatusPages feature, is there a way to have code common to any exception? I'm trying to log the stack trace before returning a specific response code, and so far my code looks like this:
Copy code
exception<NoSuchElementException> {
            cause ->
            log.error(cause.localizedMessage)
            val sw = StringWriter()
            cause.printStackTrace(PrintWriter(sw))
            val exceptionAsString = sw.toString()
            log.error(exceptionAsString)
            call.response.status(HttpStatusCode.NotFound)
            call.respondText(cause.message.toString())
        }
        exception<InvalidJwtException> {
            cause ->
            log.error(cause.localizedMessage)
            val sw = StringWriter()
            cause.printStackTrace(PrintWriter(sw))
            val exceptionAsString = sw.toString()
            log.error(exceptionAsString)
            call.response.status(HttpStatusCode.Unauthorized)
            call.respond(cause.message.toString())
        }