rodolpho.couto
11/05/2020, 6:36 PMdata 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()
}
}
}
The CustomContext
is null inside onError
function. Any ideas?