Since handling this scenario for the first time, asking to know which is best approach.
Here for all the DataIntegrityViolationException
, sending the same error message
@Override
public boolean saveParam(ParamDto dto) throws ParamException
{
try
{
return super.save(dto);
}
catch(DataIntegrityViolationException e)
{
throw new ParamException(ParamException.INTERNAL_SERVER_ERROR, messageSource.getMessage(CodeEnum.DUPLICATE_APP.getValue(), new Object[] { dto.getParamKey() }, Locale.ENGLISH));
}
catch (GenericException ge)
{
throw new ParamException(ge, ge.getRootCauseMessage());
}
}
How can we give different customs messages for the same exception. Do we need to check the message string ?
Here having 2 different kind of exception under DataIntegrityViolationException
.
"ERROR: value too long for type character(1)" (id=172) ""
"ERROR: duplicate key value violates unique constraint "uk_param_key"\n Detail: Key (param_key)=(Test1) already exists."