rodolpho.couto
data class CustomContext(val value: String) : AbstractCoroutineContextElement(Key) { object Key : CoroutineContext.Key<CustomContext> } @SpringBootApplication class Application { @Bean fun router() = coRouter { GET("/test") { request -> withContext(CustomContext(value = "test")) { println(coroutineContext[CustomContext.Key]?.value) throw IllegalArgumentException() } } onError<IllegalArgumentException> { throwable, request -> println(coroutineContext[CustomContext.Key]?.value) status(INTERNAL_SERVER_ERROR).buildAndAwait() } } }
CustomContext
onError
A modern programming language that makes developers happier.