Reputation: 23333
I've created class that implements implements ExceptionMapper<WebApplicationException>
and registered it by environment.addProvider(new WebApplicationExceptionMapper());
. My custom mapper works but only for some exceptions extended from WebApplicationException
. For example it doesn't work for ConflictException
and it also doesn't work for my custom exceptions with following constructor:
public ConflictException(URI location, Object entity) {
super(Response.status(Response.Status.CONFLICT).location(location).entity(entity).build());
}
It will work if I'll remove super(Response.status....
. This is very strange and I can't explain this. I'm not sure is it Jersey
or Dropwizard
behaviour.
What is correct way to configure mapper for all WebApplicationException
and subclasses? Can you explain problems that I have?
Upvotes: 3
Views: 4350
Reputation: 1171
May be a little too late, but found this to work.
for dropwizard 0.8 and above
in the yaml configuration
server:
registerDefaultExceptionMappers: false
This would disable the DWs default exception mapper, then add your own exception mappers
// Register the custom ExceptionMapper(s)
environment.jersey().register(new RestErrorsHandler());
Source: github issue
Upvotes: 5
Reputation: 1403
This post shows how to create custom ExceptionMappers:
http://gary-rowe.com/agilestack/2012/10/23/how-to-implement-a-runtimeexceptionmapper-for-dropwizard/
Perhaps this post could also help, if you having problems with your custom exceptionMappers: http://thoughtspark.org/2013/02/25/dropwizard-and-jersey-exceptionmappers/
Upvotes: 0