I'm using GenericExceptionHandling
on the application level
@ControllerAdvice
public class GlobalExceptionHandler {
// Handle the DataIntegrityViolationException
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<?> customDataIntegrityViolationException
(DataIntegrityViolationException exception) {
String message = "This {key} is already exist";
ErrorDetails errorDetals = new ErrorDetails(new Date(), message, exception.getCause().getMessage());
return new ResponseEntity<Object>(errorDetals, HttpStatus.UNPROCESSABLE_ENTITY);
}
}
I want to get the name of the key that's causing the error. I.e. {key}. I googled but didn't get any answer that solves my problem. If anyone has done this kind of work please suggest a way.