Skip to content

Commit

Permalink
Add explicit coroutine context to CoWebExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
earlgrey02 committed Jun 6, 2024
1 parent 10e7dc7 commit 40d9eee
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package org.springframework.web.server
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactor.mono
import reactor.core.publisher.Mono
import kotlin.coroutines.CoroutineContext

abstract class CoWebExceptionHandler : WebExceptionHandler {
final override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono<Void> =
mono(Dispatchers.Unconfined) { coHandle(exchange, ex) }.then()

final override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono<Void> {
val context = exchange.attributes[CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext?
return mono(context ?: Dispatchers.Unconfined) { coHandle(exchange, ex) }.then()
}

protected abstract suspend fun coHandle(exchange: ServerWebExchange, ex: Throwable)
}

0 comments on commit 40d9eee

Please sign in to comment.