So I am facing a problem with handling all sorts of exceptions within spring-boot application. Basically project is structured:
back-end (services, repositories) <----- RestControllers <---- UI (React\Angular)
The gist is that UI depends on Rest API wile rest API depends on Back-end services
Now - Rest API is designed around its own RESOURCES and back-end services around their own DTO's.
Currently validation is done in two places: RestControllers and Services while UI just displays the responses (validation errors).
Problem:
The usual validation problem in RestController's is acquiring valid resource. And this is handled nicely with combination of @Valid, JSR 303 Bean Validation and @ControllerAdvice. And this translates to something like:
[field: ..., error: ...]...
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 [field: ..., 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 ?