You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following problem/question: what am I doing wrong?
I have an application with a MainService where I call the @Transactional method response() via REST API.
Inside the response() method, I call a method from another service, NastedService.anotherSave(), which is also @Transactional.
Sometimes the NastedService.anotherSave() method throws a database-related exception, which is a normal situation.
I would like to catch all exceptions (related to the database) from the MainService and NastedService using an interceptor. (ExceptionRepacker)
I want to wrap the exceptions so that the REST layer in the application only has information about domain/service errors.
My case makes more sense if the application is divided into artifacts, per layer.
Unfortunately, the Interceptor does not catch errors thrown by Hibernate. Interestingly, if I throw an exception manually, the Interceptor works. For example:
@Override@TransactionalpublicvoidanotherSave(inti) {
// Expect that the interceptor will catch the error"if (i % 5 == 0) {
// throw exception, invalid save try: interceptor does not catch itProductentity = newProduct();
productRepository.save(entity);
// throw the same exception as in first case: interceptor does catch it//try {// Thread.sleep(500);//} catch (InterruptedException e) {// throw new RuntimeException(e);//}//throw new org.hibernate.exception.ConstraintViolationException("asd", null, null);
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone.
I have the following problem/question: what am I doing wrong?
MainService
where I call the@Transactional
methodresponse()
via REST API.response()
method, I call a method from another service,NastedService.anotherSave()
, which is also@Transactional
.NastedService.anotherSave()
method throws a database-related exception, which is a normal situation.MainService
andNastedService
using an interceptor. (ExceptionRepacker
)I want to wrap the exceptions so that the REST layer in the application only has information about domain/service errors.
My case makes more sense if the application is divided into artifacts, per layer.
I am posting a sample application below:
https://github.com/matadini/interceptor-bug
I would be grateful in advance for any comments/advice.
Beta Was this translation helpful? Give feedback.
All reactions