@@ -57,15 +57,17 @@ final class RouterState {
57
57
private final TreeSet <RouteImpl > routes ;
58
58
private final int orderSequence ;
59
59
private final Map <Integer , Handler <RoutingContext >> errorHandlers ;
60
+ private final Handler <RoutingContext > uncaughtErrorHandler ;
60
61
private final Handler <Router > modifiedHandler ;
61
62
private final AllowForwardHeaders allowForward ;
62
63
private final Map <String , Object > metadata ;
63
64
64
- public RouterState (RouterImpl router , TreeSet <RouteImpl > routes , int orderSequence , Map <Integer , Handler <RoutingContext >> errorHandlers , Handler <Router > modifiedHandler , AllowForwardHeaders allowForward , Map <String , Object > metadata ) {
65
+ public RouterState (RouterImpl router , TreeSet <RouteImpl > routes , int orderSequence , Map <Integer , Handler <RoutingContext >> errorHandlers , final Handler < RoutingContext > uncaughtErrorHandler , Handler <Router > modifiedHandler , AllowForwardHeaders allowForward , Map <String , Object > metadata ) {
65
66
this .router = router ;
66
67
this .routes = routes ;
67
68
this .orderSequence = orderSequence ;
68
69
this .errorHandlers = errorHandlers ;
70
+ this .uncaughtErrorHandler = uncaughtErrorHandler ;
69
71
this .modifiedHandler = modifiedHandler ;
70
72
this .allowForward = allowForward ;
71
73
this .metadata = metadata ;
@@ -78,6 +80,7 @@ public RouterState(RouterImpl router) {
78
80
0 ,
79
81
null ,
80
82
null ,
83
+ null ,
81
84
AllowForwardHeaders .NONE ,
82
85
null );
83
86
}
@@ -99,6 +102,7 @@ RouterState setRoutes(Set<RouteImpl> routes) {
99
102
new TreeSet <>(routeComparator ),
100
103
this .orderSequence ,
101
104
this .errorHandlers ,
105
+ this .uncaughtErrorHandler ,
102
106
this .modifiedHandler ,
103
107
this .allowForward ,
104
108
this .metadata );
@@ -119,6 +123,7 @@ RouterState addRoute(RouteImpl route) {
119
123
routes ,
120
124
this .orderSequence ,
121
125
this .errorHandlers ,
126
+ this .uncaughtErrorHandler ,
122
127
this .modifiedHandler ,
123
128
this .allowForward ,
124
129
this .metadata );
@@ -130,6 +135,7 @@ RouterState clearRoutes() {
130
135
new TreeSet <>(routeComparator ),
131
136
this .orderSequence ,
132
137
this .errorHandlers ,
138
+ null ,
133
139
this .modifiedHandler ,
134
140
this .allowForward ,
135
141
this .metadata );
@@ -147,6 +153,7 @@ RouterState removeRoute(RouteImpl route) {
147
153
routes ,
148
154
this .orderSequence ,
149
155
this .errorHandlers ,
156
+ this .uncaughtErrorHandler ,
150
157
this .modifiedHandler ,
151
158
this .allowForward ,
152
159
this .metadata );
@@ -162,6 +169,7 @@ RouterState incrementOrderSequence() {
162
169
this .routes ,
163
170
this .orderSequence + 1 ,
164
171
this .errorHandlers ,
172
+ this .uncaughtErrorHandler ,
165
173
this .modifiedHandler ,
166
174
this .allowForward ,
167
175
this .metadata );
@@ -173,6 +181,7 @@ RouterState setOrderSequence(int orderSequence) {
173
181
this .routes ,
174
182
orderSequence ,
175
183
this .errorHandlers ,
184
+ this .uncaughtErrorHandler ,
176
185
this .modifiedHandler ,
177
186
this .allowForward ,
178
187
this .metadata );
@@ -188,16 +197,20 @@ RouterState setErrorHandlers(Map<Integer, Handler<RoutingContext>> errorHandlers
188
197
this .routes ,
189
198
this .orderSequence ,
190
199
errorHandlers ,
200
+ this .uncaughtErrorHandler ,
191
201
this .modifiedHandler ,
192
202
this .allowForward ,
193
203
this .metadata );
194
204
}
195
205
196
206
Handler <RoutingContext > getErrorHandler (int errorCode ) {
197
207
if (errorHandlers != null ) {
198
- return errorHandlers .get (errorCode );
208
+ final Handler <RoutingContext > errorHandler = errorHandlers .get (errorCode );
209
+ if (errorHandler != null ) {
210
+ return errorHandler ;
211
+ }
199
212
}
200
- return null ;
213
+ return uncaughtErrorHandler ;
201
214
}
202
215
203
216
RouterState putErrorHandler (int errorCode , Handler <RoutingContext > errorHandler ) {
@@ -206,6 +219,7 @@ RouterState putErrorHandler(int errorCode, Handler<RoutingContext> errorHandler)
206
219
this .routes ,
207
220
this .orderSequence ,
208
221
this .errorHandlers == null ? new HashMap <>() : new HashMap <>(errorHandlers ),
222
+ this .uncaughtErrorHandler ,
209
223
this .modifiedHandler ,
210
224
this .allowForward ,
211
225
this .metadata );
@@ -214,6 +228,18 @@ RouterState putErrorHandler(int errorCode, Handler<RoutingContext> errorHandler)
214
228
return newState ;
215
229
}
216
230
231
+ RouterState setUncaughtErrorHandler (Handler <RoutingContext > errorHandler ) {
232
+ return new RouterState (
233
+ this .router ,
234
+ this .routes ,
235
+ this .orderSequence ,
236
+ this .errorHandlers ,
237
+ errorHandler ,
238
+ this .modifiedHandler ,
239
+ this .allowForward ,
240
+ this .metadata );
241
+ }
242
+
217
243
public Handler <Router > getModifiedHandler () {
218
244
return modifiedHandler ;
219
245
}
@@ -224,6 +250,7 @@ public RouterState setModifiedHandler(Handler<Router> modifiedHandler) {
224
250
this .routes ,
225
251
this .orderSequence ,
226
252
this .errorHandlers ,
253
+ this .uncaughtErrorHandler ,
227
254
modifiedHandler ,
228
255
this .allowForward ,
229
256
this .metadata );
@@ -235,6 +262,7 @@ public RouterState setAllowForward(AllowForwardHeaders allow) {
235
262
this .routes ,
236
263
this .orderSequence ,
237
264
this .errorHandlers ,
265
+ this .uncaughtErrorHandler ,
238
266
this .modifiedHandler ,
239
267
allow ,
240
268
this .metadata );
@@ -256,6 +284,7 @@ public RouterState putMetadata(String key, Object value) {
256
284
this .routes ,
257
285
this .orderSequence ,
258
286
this .errorHandlers ,
287
+ this .uncaughtErrorHandler ,
259
288
this .modifiedHandler ,
260
289
this .allowForward ,
261
290
Collections .unmodifiableMap (metadata ));
0 commit comments