Hey guys, is there a way to access the coroutine c...
# spring
r
Hey guys, is there a way to access the coroutine context from an exception handler? Example:
Copy code
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()
        }
    }
}
The
CustomContext
is null inside
onError
function. Any ideas?