Skip to content

Commit

Permalink
return None from mailchimp_contact_for_user method if api call fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Moggach committed Jul 16, 2024
1 parent 4c62cff commit 21ed633
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/utils/mailchimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ def mailchimp_contact_for_user(user: User, list_id=settings.MAILCHIMP_LIST_ID):
member = apply_gdpr_consent(member)
return member
except MailchimpApiClientError:
member = mailchimp.lists.add_list_member(
list_id,
{
"email_address": user.primary_email,
"merge_fields": {"FNAME": user.first_name, "LNAME": user.last_name},
"status": "subscribed" if user.gdpr_email_consent else "unsubscribed",
},
)
member = apply_gdpr_consent(member)
return member
try:
member = mailchimp.lists.add_list_member(
list_id,
{
"email_address": user.primary_email,
"merge_fields": {"FNAME": user.first_name, "LNAME": user.last_name},
"status": "subscribed" if user.gdpr_email_consent else "unsubscribed",
},
)
member = apply_gdpr_consent(member)
return member
except MailchimpApiClientError as e:
print(f"Failed to add list member: {e}")
return None


def tag_user_in_mailchimp(user: User, tags_to_enable=list(), tags_to_disable=list()):
Expand Down

0 comments on commit 21ed633

Please sign in to comment.