Hi all,

I am currently using Dropwizard 1.0.3. In my application, I have a resource 
method that reads a path parameter and map it to a Mustache view (e.g. 
/static/{viewName} maps to a Mustache template called 
/views/{viewName}.mustache). For error handling, I want to return a 404 
error w/ a custom page when the view template does not exist.

To achieve that, I want to handle it naturally and let the Mustache view 
renderer code propagate a WebApplicationException up, where I would then 
capture and return a custom 404 error page via an ExceptionMapper. However, 
the custom ExceptionMapper doesn't capture the exception, leading me to 
believe that either there is a bug with the exception handling code, or I 
don't fully understand how the exception handling works.

>From what I can tell by reading the Mustache and Dropwizard code, I believe 
that the exception is propagated up as follows:

1. DefaultMustacheFactory (part of Mustache) throws a 
MustacheNotFoundException
2. MustacheViewRenderer (part of dropwizard-views-mustache) catches the 
above exception and re-throw it as a RuntimeException
3. ViewMessageBodyWriter (part of dropwizard-views) catches the above 
exception and re-throw it as a WebApplicationException
4. My custom ExceptionHandler<WebApplicationException> intercepts the above 
exception and does something with it

Through debugging using breakpoints in Eclipse, I can tell that #1 - #3 are 
done, and #4 is not done. I can only think of the fact that the exception 
thrown at the writing phase is already too late or in the wrong area for 
the ExceptionHandler to capture, or that there is another ExceptionHandler 
at work taking over. In the last case, I looked at the default 
ExceptionHandlers in Dropwizard and can only see the LoggingExceptionMapper 
being the only culprit. However I think it's unlikely because the same 
custom ExceptionHandler can handle NotFoundExceptions (which is also a 
sub-class of WebApplicationException) correctly.

Any assistance on this matter would be greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to