What is the preferred method of handling "duplicate contact" errors?
$ConstantContact = new ConstantContact ( "oauth2", $apikey, $username, $accessToken );
$ContactLists = $ConstantContact->getLists();
// echo print_r($ContactLists);
$Contact = new Contact();
$Contact->emailAddress = $_POST['emailaddress'];
$Contact->firstName = $_POST['firstname'];
$Contact->lastName = $_POST['lastname'];
$Contact->lists = $_POST['lists'];
$NewContact = $ConstantContact->addContact($Contact);
echo "<script>alert('Congrats! You are added to the mailing list.');</script>";
RIght now, this gets placed within the markup of my page, and I'd like to hide it and replace it with a nicer error message to the user:
Constant Contact HTTP Request Exception: Error 409: Email address _(myemail)_ is already a contact
Fatal error: Call to a member function Attributes() on a non-object in /data/14/1/78/53/1078053/user/1118909/htdocs/ccontact/Components.php on line 208
If you look a tthe sample code I posted on your other forum post here, I first search to see if the email address exists, then I add a new contact if it doesn't, and update the existing contact if it does already exist in the account. That's my preference. However, you could also check to see if they exist (like I do), and then not update them and echo that they are already subscribed.
API Support Specialist