I have a controller advice that handles the exceptional behavior in my REST controller and I came across a situation when I have to conditionally process SQLIntegrityConstraintViolationException
that have a certain message (the one for duplicate keys), returning a 409
, letting the other ones be handled by the default handler (returning a 500
error code).
I am thinking of 2 possible ways to achieve that:
- Throwing a new bare-boned
Exception
on the else branch on my condition, so the handling is done by Spring. - Explicitly calling the general exception handler (like
return handleGeneralException(exception)
from inside my else branch).
I there a "proper" way to pass on a fraction of exceptions of one kind in my ControllerAdvice
to another handler than the "original" one?
EDIT 1: I would like to do something like this in my ControllerAdvice:
if (exception.getMessage.contains("something")) {
// handle exception
} else {
// pass to other handler
}