From ea5681c125ef0c33267a86f0b73da2bfdb800af7 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Tue, 15 Oct 2024 12:59:33 -0500 Subject: [PATCH] fix: move JSONDecodeError catch statement to xapi lrs --- event_routing_backends/tasks.py | 3 +-- event_routing_backends/utils/xapi_lrs_client.py | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/event_routing_backends/tasks.py b/event_routing_backends/tasks.py index fdb1f436..ae171736 100644 --- a/event_routing_backends/tasks.py +++ b/event_routing_backends/tasks.py @@ -5,7 +5,6 @@ from celery.utils.log import get_task_logger from celery_utils.persist_on_failure import LoggedPersistOnFailureTask from django.conf import settings -from json.decoder import JSONDecodeError from event_routing_backends.processors.transformer_utils.exceptions import EventNotDispatched from event_routing_backends.utils.http_client import HttpClient from event_routing_backends.utils.xapi_lrs_client import LrsClient @@ -131,7 +130,7 @@ def bulk_send_events(task, events, router_type, host_config): client_class ) ) - except (EventNotDispatched, JSONDecodeError) as exc: + except EventNotDispatched as exc: logger.exception( 'Exception occurred while trying to bulk dispatch {} events using client: {}'.format( len(events), diff --git a/event_routing_backends/utils/xapi_lrs_client.py b/event_routing_backends/utils/xapi_lrs_client.py index 1bb61745..c00c874c 100644 --- a/event_routing_backends/utils/xapi_lrs_client.py +++ b/event_routing_backends/utils/xapi_lrs_client.py @@ -1,6 +1,7 @@ """ An LRS client for xAPI stores. """ +from json.decoder import JSONDecodeError from logging import getLogger from tincan.remote_lrs import RemoteLRS @@ -72,7 +73,11 @@ def bulk_send(self, statement_data): """ logger.debug('Sending {} xAPI statements to {}'.format(len(statement_data), self.URL)) - response = self.lrs_client.save_statements(statement_data) + try: + response = self.lrs_client.save_statements(statement_data) + except JSONDecodeError as e: + logger.warning(f"Events already in LRS: {response.request.content}") + return if not response.success: if response.response.code == 409 or response.response.code == 204: