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 error. i.e. {key}. I googled but didn't get any answer that solve my problem. If anyone have done this kind of work please tell.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…