Skip to content

Commit

Permalink
Catch the integrity error
Browse files Browse the repository at this point in the history
  • Loading branch information
zachaysan committed Dec 9, 2024
1 parent de9ea30 commit 987fabc
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions api/integrations/lead_tracking/hubspot/services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.db import IntegrityError
from rest_framework.request import Request

from integrations.lead_tracking.hubspot.constants import HUBSPOT_COOKIE_NAME
Expand All @@ -17,13 +18,18 @@ def register_hubspot_tracker(request: Request) -> None:
)
return

logger.info(
f"Creating HubspotTracker instance for user {request.user.email} with cookie {hubspot_cookie}"
)

HubspotTracker.objects.update_or_create(
user=request.user,
defaults={
"hubspot_cookie": hubspot_cookie,
},
)
try:
HubspotTracker.objects.update_or_create(
user=request.user,
defaults={
"hubspot_cookie": hubspot_cookie,
},
)
logger.info(
f"Created HubspotTracker instance for user {request.user.email} with cookie {hubspot_cookie}"
)
except IntegrityError:
logger.info(
f"HubspotTracker could not be created for user {request.user.email}"
f" due to cookie conflict with cookie {hubspot_cookie}"
)

0 comments on commit 987fabc

Please sign in to comment.