Ad throw an exception without throwing it

I have a pair of EJBs that are being called from a jax-rs web service. However, every time I call one of the EJB methods, I intercept the call with an interceptor. This interceptor checks the parameters for the API key, and if it is absent or does not exist in my database, it will throw an exception that I want to catch in my jax-rs code. However, since my jax-rs class is not aware of the possibility of throwing this exception, although the exception may be a checked exception, what would be best here?

  • Declaring my EJB to throw exceptions (without throwing them)
  • How to exclude an exception and exclude this exception?
  • Something else?
+5
source share
2 answers

I realized that throwing an unchecked exception would be best. Then I use the exception mapping block to catch the exception and handle it.

https://docs.oracle.com/javaee/6/api/javax/ws/rs/ext/ExceptionMapper.html

The only thing left is to suppress the output of the exception to the log files.

+1
source

An interceptor may throw several RuntimeException (for example, InvalidParametersException ). And you can create a special servlet that will handle all InvalidParametersException . To do this, you need to create a special mapping in web.xml.

0
source

Source: https://habr.com/ru/post/1247686/


All Articles