@ControllerAdvice
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(DataIntegrityViolationException.class)
protected ResponseEntity<ApiErrorDTO> handleDataIntegrityViolation(DataIntegrityViolationException ex) {
logger.error("handle DataIntegrityViolationException:", ex);
String message = ... // ???
return new ApiErrorDTO(message);
}
}
How to determine correctly which type of error was the cause of this exception?
I need to at least distinguish the violation of database integrity constraints from the insertion of duplicates
I'am found information about SQLExceptionTranslator
, but I don't understand how I can use it?
I need help with this