I am using Spring 4 and Tomcat. The issue is sometimes I have to throw a (custom) RuntimeException in my filter (The control has not even reached the controller). The issue is since I am not throwing an exception that tomcat understands, it gets converted to 500 (internal server error). I believe a 403 Forbidden would be better than a 500 (For my custom exception). I have looked at @ExceptionHandler
and @ControllerAdvice
annotations. But these work only if the control reaches the controller.
As of now I am manually setting the status to 403 in the HTTPResponse
in my filter. Is there a better way of handling this scenario?