Check actual error code for duplicate row inserted in newsletter subscriptions

This commit is contained in:
Alex Cabal 2022-06-17 11:13:33 -05:00
parent 69df5ac43a
commit f7558eab3a

View file

@ -31,10 +31,13 @@ class NewsletterSubscriber extends PropertiesBase{
Db::Query('insert into NewsletterSubscribers (Email, Uuid, FirstName, LastName, IsConfirmed, IsSubscribedToNewsletter, IsSubscribedToSummary, Timestamp) values (?, ?, ?, ?, ?, ?, ?, utc_timestamp());', [$this->Email, $this->Uuid, $this->FirstName, $this->LastName, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary]);
}
catch(PDOException $ex){
if($ex->getCode() == '23000'){
if($ex->errorInfo[1] == 1062){
// Duplicate unique key; email already in use
throw new Exceptions\NewsletterSubscriberExistsException();
}
else{
throw $ex;
}
}
$this->NewsletterSubscriberId = Db::GetLastInsertedId();