Is it possible to include a message in a BadRequestException
so when the user sees a response code a 400, he/she can also figure out why?
The scenario would be something like this, simplified:
public Entity getEntityWithOptions(@PathParam("id") String id, @QueryParam("option") String optValue) {
if (optValue != null) {
// Option is an enum
try {
Option option = Option.valueOf(optValue);
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
}
return new Entity(option);
}
return new Entity();
}
I know this can be done returning a Response
object instead, but I wouldn't want that.
Is this possible? Maybe with an ExceptionMapper<BadRequestException>
? Or this cannot be done since BadRequestException
is already a Jersey-specific exception?