Dropwizard : Exception Handling, giving custom error JSON error messages to client Dropwizard : Exception Handling, giving custom error JSON error messages to client json json

Dropwizard : Exception Handling, giving custom error JSON error messages to client


You can add your own subclass of WebApplicationException like this:

public class ObjectNotFoundException extends WebApplicationException {  public ObjectNotFoundException() {    super(Responses.notFound().build());  }  public ObjectNotFoundException(String message) {    super(Response.status(Responses.NOT_FOUND).    entity(message).type("text/plain").build());  }}

See the documentation for more information. You can also use ExceptionMappers if that makes more sense for your application.