From 14f5c2a79926f1336024a5a1fe02d0e37aaaaf1c Mon Sep 17 00:00:00 2001 From: akmiller01 Date: Tue, 9 Jul 2024 07:25:10 -0400 Subject: [PATCH] Error proof API --- di_website/api/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/di_website/api/views.py b/di_website/api/views.py index 0a115bd7d..57f144c18 100644 --- a/di_website/api/views.py +++ b/di_website/api/views.py @@ -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 @@ -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)