1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -44,7 +44,10 @@ public class HandlerResult {
44
44
private final BindingContext bindingContext ;
45
45
46
46
@ Nullable
47
- private Function <Throwable , Mono <HandlerResult >> exceptionHandler ;
47
+ private DispatchExceptionHandler exceptionHandler ;
48
+
49
+ @ Nullable
50
+ private Function <Throwable , Mono <HandlerResult >> exceptionHandlerFunction ;
48
51
49
52
50
53
/**
@@ -124,21 +127,50 @@ public Model getModel() {
124
127
return this .bindingContext .getModel ();
125
128
}
126
129
130
+ /**
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.
136
+ * @param exceptionHandler the exception handler to use
137
+ * @since 6.0
138
+ */
139
+ public HandlerResult setExceptionHandler (DispatchExceptionHandler exceptionHandler ) {
140
+ this .exceptionHandler = exceptionHandler ;
141
+ return this ;
142
+ }
143
+
144
+ /**
145
+ * Return the {@link #setExceptionHandler(DispatchExceptionHandler)
146
+ * configured} exception handler.
147
+ * @since 6.0
148
+ */
149
+ @ Nullable
150
+ public DispatchExceptionHandler getExceptionHandler () {
151
+ return this .exceptionHandler ;
152
+ }
153
+
127
154
/**
128
155
* Configure an exception handler that may be used to produce an alternative
129
156
* result when result handling fails. Especially for an async return value
130
157
* errors may occur after the invocation of the handler.
131
158
* @param function the error handler
132
159
* @return the current instance
160
+ * @deprecated in favor of {@link #setExceptionHandler(DispatchExceptionHandler)}
133
161
*/
162
+ @ Deprecated (since = "6.0" , forRemoval = true )
134
163
public HandlerResult setExceptionHandler (Function <Throwable , Mono <HandlerResult >> function ) {
135
- this .exceptionHandler = function ;
164
+ this .exceptionHandler = (exchange , ex ) -> function .apply (ex );
165
+ this .exceptionHandlerFunction = function ;
136
166
return this ;
137
167
}
138
168
139
169
/**
140
170
* Whether there is an exception handler.
171
+ * @deprecated in favor of checking via {@link #getExceptionHandler()}
141
172
*/
173
+ @ Deprecated (since = "6.0" , forRemoval = true )
142
174
public boolean hasExceptionHandler () {
143
175
return (this .exceptionHandler != null );
144
176
}
@@ -147,9 +179,12 @@ public boolean hasExceptionHandler() {
147
179
* Apply the exception handler and return the alternative result.
148
180
* @param failure the exception
149
181
* @return the new result or the same error if there is no exception handler
182
+ * @deprecated without a replacement; for internal invocation only, not used as of 6.0
150
183
*/
184
+ @ Deprecated (since = "6.0" , forRemoval = true )
151
185
public Mono <HandlerResult > applyExceptionHandler (Throwable failure ) {
152
- return (this .exceptionHandler != null ? this .exceptionHandler .apply (failure ) : Mono .error (failure ));
186
+ return (this .exceptionHandlerFunction != null ?
187
+ this .exceptionHandlerFunction .apply (failure ) : Mono .error (failure ));
153
188
}
154
189
155
190
}
0 commit comments