Skip to content

Commit fb22044

Browse files
committed
Polishing
See gh-22991
1 parent da4b539 commit fb22044

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/DispatchExceptionHandler.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,29 @@
2323
/**
2424
* Contract to map a {@link Throwable} to a {@link HandlerResult}.
2525
*
26+
* <p>Supported by {@link DispatcherHandler} when used in the following ways:
27+
* <ul>
28+
* <li>Set on a {@link HandlerResult#setExceptionHandler HandlerResult}, allowing
29+
* a {@link HandlerAdapter} to apply its exception handling to deferred exceptions
30+
* from asynchronous return values, and to response rendering.
31+
* <li>Implemented by a {@link HandlerAdapter} in order to handle exceptions that
32+
* occur before a request is mapped to a handler.
33+
* </ul>
34+
*
2635
* @author Rossen Stoyanchev
2736
* @since 6.0
37+
* @see HandlerAdapter
38+
* @see HandlerResult#setExceptionHandler(DispatchExceptionHandler)
2839
*/
2940
public interface DispatchExceptionHandler {
3041

3142
/**
32-
* Handler the given exception and resolve it to {@link HandlerResult} that
33-
* can be used for rendering an HTTP response.
43+
* Handle the given exception, mapping it to a {@link HandlerResult} that can
44+
* then be used to render an HTTP response.
3445
* @param exchange the current exchange
3546
* @param ex the exception to handle
36-
* @return a {@code Mono} that emits a {@code HandlerResult} or the original exception
47+
* @return a {@code Mono} that emits a {@code HandlerResult} or an error
48+
* signal with the original exception if it remains not handled
3749
*/
3850
Mono<HandlerResult> handleError(ServerWebExchange exchange, Throwable ex);
3951

spring-webflux/src/main/java/org/springframework/web/reactive/HandlerAdapter.java

+27-20
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
import org.springframework.web.server.ServerWebExchange;
2222

2323
/**
24-
* Contract that decouples the {@link DispatcherHandler} from the details of
25-
* invoking a handler and makes it possible to support any handler type.
24+
* Contract to abstract the details of invoking a handler of a given type.
2625
*
27-
* <p>A {@code HandlerAdapter} can implement {@link DispatchExceptionHandler}
28-
* if it wants to handle an exception that occurred before the request is mapped
29-
* to a handler. This allows the {@code HandlerAdapter} to expose a consistent
30-
* exception handling mechanism for any request handling error.
31-
* In Reactive Streams terms, {@link #handle} processes the onNext, while
32-
* {@link DispatchExceptionHandler#handleError} processes the onError signal
33-
* from the upstream.
26+
* <p>An implementation can also choose to be an instance of
27+
* {@link DispatchExceptionHandler} if it wants to handle exceptions that occur
28+
* before the request is successfully mapped to a handler. This allows a
29+
* {@code HandlerAdapter} to expose the same exception handling both for handler
30+
* invocation errors and for errors before a handler is selected.
31+
* In Reactive Streams terms, {@link #handle} handles the onNext signal, while
32+
* {@link DispatchExceptionHandler#handleError} handles the onError signal
33+
* from the dispatch processing chain.
3434
*
3535
* @author Rossen Stoyanchev
3636
* @author Sebastien Deleuze
@@ -46,20 +46,27 @@ public interface HandlerAdapter {
4646
boolean supports(Object handler);
4747

4848
/**
49-
* Handle the request with the given handler.
50-
* <p>Implementations are encouraged to handle exceptions resulting from the
51-
* invocation of a handler in order and if necessary to return an alternate
52-
* result that represents an error response.
53-
* <p>Furthermore since an async {@code HandlerResult} may produce an error
54-
* later during result handling implementations are also encouraged to
55-
* {@link HandlerResult#setExceptionHandler(DispatchExceptionHandler) set
56-
* an exception handler} on the {@code HandlerResult} so that may also be
57-
* applied later after result handling.
49+
* Handle the request with the given handler, previously checked via
50+
* {@link #supports(Object)}.
51+
* <p>Implementations should consider the following for exception handling:
52+
* <ul>
53+
* <li>Handle invocation exceptions within this method.
54+
* <li>{@link HandlerResult#setExceptionHandler(DispatchExceptionHandler)
55+
* Set an exception handler} on the returned {@code HandlerResult} to handle
56+
* deferred exceptions from asynchronous return values, and to handle
57+
* exceptions from response rendering.
58+
* <li>Implement {@link DispatchExceptionHandler} to extend exception
59+
* handling to exceptions that occur before a handler is selected.
60+
* </ul>
5861
* @param exchange current server exchange
5962
* @param handler the selected handler which must have been previously
6063
* checked via {@link #supports(Object)}
61-
* @return {@link Mono} that emits a single {@code HandlerResult} or none if
62-
* the request has been fully handled and doesn't require further handling.
64+
* @return {@link Mono} that emits a {@code HandlerResult}, or completes
65+
* empty if the request is fully handled; any error signal would not be
66+
* handled within the {@link DispatcherHandler}, and would instead be
67+
* processed by the chain of registered
68+
* {@link org.springframework.web.server.WebExceptionHandler}s at the end
69+
* of the {@link org.springframework.web.server.WebFilter} chain
6370
*/
6471
Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler);
6572

spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResult.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ public Model getModel() {
128128
}
129129

130130
/**
131-
* A {@link HandlerAdapter} may use this to provide an exception handler
132-
* to use to map exceptions from handling this result into an alternative
133-
* one. Especially when the return value is asynchronous, an exception is
134-
* not be produced at the point of handler invocation, but rather later when
135-
* result handling causes the actual value or an exception to be produced.
131+
* {@link HandlerAdapter} classes can set this to have their exception
132+
* handling mechanism applied to response rendering and to deferred
133+
* exceptions when invoking a handler with an asynchronous return value.
136134
* @param exceptionHandler the exception handler to use
137135
* @since 6.0
138136
*/
@@ -152,9 +150,9 @@ public DispatchExceptionHandler getExceptionHandler() {
152150
}
153151

154152
/**
155-
* Configure an exception handler that may be used to produce an alternative
156-
* result when result handling fails. Especially for an async return value
157-
* errors may occur after the invocation of the handler.
153+
* {@link HandlerAdapter} classes can set this to have their exception
154+
* handling mechanism applied to response rendering and to deferred
155+
* exceptions when invoking a handler with an asynchronous return value.
158156
* @param function the error handler
159157
* @return the current instance
160158
* @deprecated in favor of {@link #setExceptionHandler(DispatchExceptionHandler)}

spring-webflux/src/main/java/org/springframework/web/reactive/HandlerResultHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.web.server.ServerWebExchange;
2222

2323
/**
24-
* Process the {@link HandlerResult}, usually returned by an {@link HandlerAdapter}.
24+
* Process the {@link HandlerResult}, usually returned by a {@link HandlerAdapter}.
2525
*
2626
* @author Rossen Stoyanchev
2727
* @author Sebastien Deleuze

0 commit comments

Comments
 (0)