Skip to content

Commit

Permalink
Error proof API
Browse files Browse the repository at this point in the history
  • Loading branch information
akmiller01 committed Jul 9, 2024
1 parent 518bf43 commit 14f5c2a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions di_website/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.http import JsonResponse, HttpResponse
from django.views.decorators.http import require_http_methods
from django.db.utils import DataError

from github import Github
from wagtail.models import Site
Expand Down Expand Up @@ -144,9 +145,14 @@ def post_cookie_consent_log_entry(request):
token = json_data.pop('token')
client_ip = get_client_ip(request)
anon_ip = anonymise_ip_address(client_ip)
if anon_ip == '0':
anon_ip = '0.0.0.0'
json_data['anonymised_ip_address'] = anon_ip
CookieConsentLogEntry.objects.update_or_create(
token=token,
defaults=json_data
)
try:
CookieConsentLogEntry.objects.update_or_create(
token=token,
defaults=json_data
)
except DataError:
pass
return HttpResponse(status=204)

0 comments on commit 14f5c2a

Please sign in to comment.