3

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?

fedor.belov
  • 22,343
  • 26
  • 89
  • 134
  • Hint : dropwizard have it default exception mapper. And there is no specific order in which the mappers are registered. So sometime your mapper will work and other time it may not. An idea is to remove dropwizards exception mapper. [This article](http://thoughtspark.org/2013/02/25/dropwizard-and-jersey-exceptionmappers/) may help you. – Manu Viswam Feb 05 '14 at 11:56
  • Yes, I've already done it but it doesn't help – fedor.belov Feb 06 '14 at 10:47
  • it may help : https://github.com/dropwizard/dropwizard/issues/710 – Navrattan Yadav Mar 14 '16 at 08:32

2 Answers2

5

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

austin
  • 1,171
  • 1
  • 13
  • 32
0

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/

user3280180
  • 1,393
  • 1
  • 11
  • 27