More robust call to addAddressType.

This is not strictly necessary, but it seems right to me that we trap
the error and rollback ourselves here as well.
This commit is contained in:
Bradley M. Kuhn 2015-12-16 20:24:24 -08:00
parent 6e57396399
commit e3cf1665d9

View file

@ -196,13 +196,21 @@ sub addEmailAddress($$$$) {
die "addEmailAddress: invalid id, $id" unless $self->_verifyId($id); die "addEmailAddress: invalid id, $id" unless $self->_verifyId($id);
die "addEmailAddress:: invalid email address, $emailAddressType" die "addEmailAddress: invalid email address, $emailAddressType"
unless defined $emailAddressType and Mail::RFC822::Address::valid($emailAddress); unless defined $emailAddressType and Mail::RFC822::Address::valid($emailAddress);
$self->_beginWork(); $self->_beginWork();
my $addressTypeId = $self->addAddressType($emailAddressType); my $addressTypeId;
eval {
$addressTypeId = $self->addAddressType($emailAddressType);
};
if ($@ or not defined $addressTypeId) {
my $err = $@;
$err = "addEmailAddress: unable to addAddressType" if (not defined $err);
$self->_rollback();
die $@ if $@;
}
my $sth = $self->dbh->prepare("INSERT INTO email_address(email_address, type_id, date_encountered)" . my $sth = $self->dbh->prepare("INSERT INTO email_address(email_address, type_id, date_encountered)" .
"VALUES( ?, ?, date('now'))"); "VALUES( ?, ?, date('now'))");