I have a custom exception class annotated to return a given HttpStatus
:
@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason=\"Invalid parameter\")
Annotations are meant to be static, and can't be set dynamically from your class. I suggest creating a subclass of your BadRequestException
for every type of failure scenario and annotating them differently.
This doesn't just serve as a workaround -- if you're hiding the details regarding what went wrong in the reason
message, then you're losing flexibility because any code that catches a BadRequestException
will have to deal with all failure scenarios the same way.