Skip to content

Commit

Permalink
fix: move JSONDecodeError catch statement to xapi lrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 15, 2024
1 parent c650d4a commit ea5681c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions event_routing_backends/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 6 additions & 1 deletion event_routing_backends/utils/xapi_lrs_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Check warning on line 80 in event_routing_backends/utils/xapi_lrs_client.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/utils/xapi_lrs_client.py#L79-L80

Added lines #L79 - L80 were not covered by tests

if not response.success:
if response.response.code == 409 or response.response.code == 204:
Expand Down

0 comments on commit ea5681c

Please sign in to comment.