|
| 1 | +/* |
| 2 | + * Copyright 2002-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
1 | 17 | package org.springframework.web.server
|
2 | 18 |
|
3 | 19 | import kotlinx.coroutines.Dispatchers
|
4 | 20 | import kotlinx.coroutines.reactor.mono
|
5 | 21 | import reactor.core.publisher.Mono
|
6 | 22 | import kotlin.coroutines.CoroutineContext
|
7 | 23 |
|
| 24 | +/** |
| 25 | + * Kotlin-specific implementation of the [WebExceptionHandler] interface that allows for |
| 26 | + * using coroutines, including [kotlin.coroutines.CoroutineContext] propagation. |
| 27 | + * |
| 28 | + * @author Sangyoon Jeong |
| 29 | + * @since 6.2 |
| 30 | + */ |
8 | 31 | abstract class CoWebExceptionHandler : WebExceptionHandler {
|
| 32 | + |
9 | 33 | final override fun handle(exchange: ServerWebExchange, ex: Throwable): Mono<Void> {
|
10 | 34 | val context = exchange.attributes[CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext?
|
11 | 35 | return mono(context ?: Dispatchers.Unconfined) { coHandle(exchange, ex) }.then()
|
|
0 commit comments