So I am facing a problem with handling all sorts of exceptions within
spring-boot application. Basically project is structured:
back-end (services, repositories) <-----
The gist is that
UI depends on
Rest API wile rest API depends on
Rest API is designed around its own RESOURCES and
back-end services around their own
Currently validation is done in two places:
UI just displays the responses (validation errors).
The usual validation problem in
RestController's is acquiring valid
resource. And this is handled nicely with combination of
JSR 303 Bean Validation and
@ControllerAdvice. And this translates to something like:
But what about other problems ? DB Constraint exceptions e.g. ? So validation can also be done in
service layer but then exceptions no longer are adhering same standard as [
error: ...]. Also exception thrown by
service needs to be translated into specific response RESOURCE. Now there is more than one error resource and this would only keep on growing.
Given the similar situation, what are best practices in such situation ?