I am trying to determine if it is possible to setup an interceptor like solution on a REST resource such that if an exception is thrown I can log the exception and change the response returned. I basically don’t want to wrap all my REST resources with try/catch blocks. If a REST resource was managed I would just use an @Interceptor on all of my calls but since it is not managed that seems to be out of the question.
Share
You can use an implementation
javax.ws.rs.ext.ExceptionMapper. Let’s suppose that your code might throw aYourFancyExceptionfrom the resources. Then you can use the following mapper:Don’t forget to annotate the mapper with
@Providerand to make your resources methods to throwYourFancyException.