In the toResponse
method, I changed this
return exception.getResponse();
to this
return Response.status(exception.getResponse().getStatus())
.entity(exception.getMessage())
.build();
The problem is the when I do this:
throw new BadRequestException("Something is wrong!");
it doesn't populate the exception's Response
's body with "Something is wrong!"
. GlassFish sees that the response body is empty and its status code is an error code, so it inserts its own response body. By populating the response body (a.k.a. entity) in the provider, this problem goes away.