@@ -57,15 +57,17 @@ final class RouterState {
5757 private final TreeSet <RouteImpl > routes ;
5858 private final int orderSequence ;
5959 private final Map <Integer , Handler <RoutingContext >> errorHandlers ;
60+ private final Handler <RoutingContext > uncaughtErrorHandler ;
6061 private final Handler <Router > modifiedHandler ;
6162 private final AllowForwardHeaders allowForward ;
6263 private final Map <String , Object > metadata ;
6364
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 ) {
6566 this .router = router ;
6667 this .routes = routes ;
6768 this .orderSequence = orderSequence ;
6869 this .errorHandlers = errorHandlers ;
70+ this .uncaughtErrorHandler = uncaughtErrorHandler ;
6971 this .modifiedHandler = modifiedHandler ;
7072 this .allowForward = allowForward ;
7173 this .metadata = metadata ;
@@ -78,6 +80,7 @@ public RouterState(RouterImpl router) {
7880 0 ,
7981 null ,
8082 null ,
83+ null ,
8184 AllowForwardHeaders .NONE ,
8285 null );
8386 }
@@ -99,6 +102,7 @@ RouterState setRoutes(Set<RouteImpl> routes) {
99102 new TreeSet <>(routeComparator ),
100103 this .orderSequence ,
101104 this .errorHandlers ,
105+ this .uncaughtErrorHandler ,
102106 this .modifiedHandler ,
103107 this .allowForward ,
104108 this .metadata );
@@ -119,6 +123,7 @@ RouterState addRoute(RouteImpl route) {
119123 routes ,
120124 this .orderSequence ,
121125 this .errorHandlers ,
126+ this .uncaughtErrorHandler ,
122127 this .modifiedHandler ,
123128 this .allowForward ,
124129 this .metadata );
@@ -130,6 +135,7 @@ RouterState clearRoutes() {
130135 new TreeSet <>(routeComparator ),
131136 this .orderSequence ,
132137 this .errorHandlers ,
138+ null ,
133139 this .modifiedHandler ,
134140 this .allowForward ,
135141 this .metadata );
@@ -147,6 +153,7 @@ RouterState removeRoute(RouteImpl route) {
147153 routes ,
148154 this .orderSequence ,
149155 this .errorHandlers ,
156+ this .uncaughtErrorHandler ,
150157 this .modifiedHandler ,
151158 this .allowForward ,
152159 this .metadata );
@@ -162,6 +169,7 @@ RouterState incrementOrderSequence() {
162169 this .routes ,
163170 this .orderSequence + 1 ,
164171 this .errorHandlers ,
172+ this .uncaughtErrorHandler ,
165173 this .modifiedHandler ,
166174 this .allowForward ,
167175 this .metadata );
@@ -173,6 +181,7 @@ RouterState setOrderSequence(int orderSequence) {
173181 this .routes ,
174182 orderSequence ,
175183 this .errorHandlers ,
184+ this .uncaughtErrorHandler ,
176185 this .modifiedHandler ,
177186 this .allowForward ,
178187 this .metadata );
@@ -188,16 +197,20 @@ RouterState setErrorHandlers(Map<Integer, Handler<RoutingContext>> errorHandlers
188197 this .routes ,
189198 this .orderSequence ,
190199 errorHandlers ,
200+ this .uncaughtErrorHandler ,
191201 this .modifiedHandler ,
192202 this .allowForward ,
193203 this .metadata );
194204 }
195205
196206 Handler <RoutingContext > getErrorHandler (int errorCode ) {
197207 if (errorHandlers != null ) {
198- return errorHandlers .get (errorCode );
208+ final Handler <RoutingContext > errorHandler = errorHandlers .get (errorCode );
209+ if (errorHandler != null ) {
210+ return errorHandler ;
211+ }
199212 }
200- return null ;
213+ return uncaughtErrorHandler ;
201214 }
202215
203216 RouterState putErrorHandler (int errorCode , Handler <RoutingContext > errorHandler ) {
@@ -206,6 +219,7 @@ RouterState putErrorHandler(int errorCode, Handler<RoutingContext> errorHandler)
206219 this .routes ,
207220 this .orderSequence ,
208221 this .errorHandlers == null ? new HashMap <>() : new HashMap <>(errorHandlers ),
222+ this .uncaughtErrorHandler ,
209223 this .modifiedHandler ,
210224 this .allowForward ,
211225 this .metadata );
@@ -214,6 +228,18 @@ RouterState putErrorHandler(int errorCode, Handler<RoutingContext> errorHandler)
214228 return newState ;
215229 }
216230
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+
217243 public Handler <Router > getModifiedHandler () {
218244 return modifiedHandler ;
219245 }
@@ -224,6 +250,7 @@ public RouterState setModifiedHandler(Handler<Router> modifiedHandler) {
224250 this .routes ,
225251 this .orderSequence ,
226252 this .errorHandlers ,
253+ this .uncaughtErrorHandler ,
227254 modifiedHandler ,
228255 this .allowForward ,
229256 this .metadata );
@@ -235,6 +262,7 @@ public RouterState setAllowForward(AllowForwardHeaders allow) {
235262 this .routes ,
236263 this .orderSequence ,
237264 this .errorHandlers ,
265+ this .uncaughtErrorHandler ,
238266 this .modifiedHandler ,
239267 allow ,
240268 this .metadata );
@@ -256,6 +284,7 @@ public RouterState putMetadata(String key, Object value) {
256284 this .routes ,
257285 this .orderSequence ,
258286 this .errorHandlers ,
287+ this .uncaughtErrorHandler ,
259288 this .modifiedHandler ,
260289 this .allowForward ,
261290 Collections .unmodifiableMap (metadata ));
0 commit comments