@@ -173,6 +173,8 @@ public boolean equals(final Object obj) {
173173
174174 private final Map <String , Renderer > rendererMap ;
175175
176+ private StatusCodeProvider sc ;
177+
176178 @ Inject
177179 public HttpHandlerImpl (final Injector injector ,
178180 final RequestScope requestScope ,
@@ -182,6 +184,7 @@ public HttpHandlerImpl(final Injector injector,
182184 final ParserExecutor parserExecutor ,
183185 final Set <Renderer > renderers ,
184186 final Set <Err .Handler > err ,
187+ final StatusCodeProvider sc ,
185188 final Charset charset ,
186189 final List <Locale > locale ) {
187190 this .injector = requireNonNull (injector , "An injector is required." );
@@ -190,6 +193,7 @@ public HttpHandlerImpl(final Injector injector,
190193 this .hasSockets = socketDefs .size () > 0 ;
191194 this .applicationPath = normalizeURI (requireNonNull (path , "An application.path is required." ));
192195 this .err = requireNonNull (err , "An err handler is required." );
196+ this .sc = sc ;
193197 this .config = injector .getInstance (Config .class );
194198 _method = Strings .emptyToNull (this .config .getString ("server.http.Method" ).trim ());
195199 this .port = config .getInt ("application.port" );
@@ -348,7 +352,7 @@ private void handleErr(final RequestImpl req, final ResponseImpl rsp, final Thro
348352 rsp .reset ();
349353
350354 // execution failed, find status code
351- Status status = statusCode (ex );
355+ Status status = sc . apply (ex );
352356
353357 rsp .header ("Cache-Control" , NO_CACHE );
354358 rsp .status (status );
@@ -419,34 +423,6 @@ private static Optional<WebSocket> findSockets(final Set<WebSocket.Definition> s
419423 return Optional .empty ();
420424 }
421425
422- private Status statusCode (final Throwable ex ) {
423- if (ex instanceof Err ) {
424- return Status .valueOf (((Err ) ex ).statusCode ());
425- }
426- /**
427- * usually a class name, except for inner classes where '$' is replaced it by '.'
428- */
429- Function <Class <?>, String > name = type -> Optional .ofNullable (type .getDeclaringClass ())
430- .map (dc -> new StringBuilder (dc .getName ())
431- .append ('.' )
432- .append (type .getSimpleName ())
433- .toString ())
434- .orElse (type .getName ());
435-
436- Config err = config .getConfig ("err" );
437- int status = -1 ;
438- Class <?> type = ex .getClass ();
439- while (type != Throwable .class && status == -1 ) {
440- String classname = name .apply (type );
441- if (err .hasPath (classname )) {
442- status = err .getInt (classname );
443- } else {
444- type = type .getSuperclass ();
445- }
446- }
447- return status == -1 ? Status .SERVER_ERROR : Status .valueOf (status );
448- }
449-
450426 private static Err handle405 (final Set <Route .Definition > routeDefs , final String method ,
451427 final String uri , final MediaType type , final List <MediaType > accept ) {
452428
0 commit comments