Fix exception type when record is duplicated