kristofdho
10/04/2017, 9:25 PMfun <T : Exception> handler(code: HttpStatusCode): suspend PipelineContext<Unit>.(T) -> Unit = {
cause ->
log.error(cause.localizedMessage)
val sw = StringWriter()
cause.printStackTrace(PrintWriter(sw))
val exceptionAsString = sw.toString()
log.error(exceptionAsString)
call.response.status(code)
call.respond(cause.message.toString())
}
exception<NoSuchElementException>(handler(HttpStatusCode.NotFound))
exception<InvalidJwtException>(handler(HttpStatusCode.Unauthorized))