Dropwizard swagger returns "no-content'

411 Views Asked by At

Hello I am using the dropwizard-swagger bundle for my dropwzard API.

I have added exception handling to return custom error codes and messages. These are rendered correctly from the API but somehow do not show up when trying the swagger UI

Inspecting console chrome shows the correct error code

I have enabled CORS in the applicatiion

 /* Configure CORS parameters */
        cors.setInitParameter("allowedOrigins", "*");
        /*
         * Allow authorization header, needed for authentication required api's
         * Note - comma with spaces does not work
         */
        cors.setInitParameter("allowedHeaders",
                "X-Requested-With,Content-Type,Accept,Origin,Authorization");
        cors.setInitParameter("allowedMethods",
                "OPTIONS,GET,PUT,POST,DELETE,HEAD");
        /* Add URL mapping */
        cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class),
                true,
                "/*");

and I have also made sure I have annotated my resources and each peration wuth the @produces annotation

@POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @AuthenticationRequired
    @Timed
    @ApiOperation(
            response = Response.class, httpMethod = "POST")
    public Response execute() {
try {
   }
catch (Exception e) {
return Response
                .status(Response.Status.BAD_REQUEST)
                .entity("NOt Found"))
                .type(MediaType.APPLICATION_JSON).build();
}
}

I am on version 0.9.3-3 of the dropwizard-swagger bundle. what ma I missing?

Note that other 200 family status codes work as expected

I also tried turning the registerDefaultExceptionMappers to false but didnt change anything

Here is the curl request generated

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{json}' 'http://myapi'

0

There are 0 best solutions below