Skip to content

Commit cf29366

Browse files
authored
Merge pull request #634 from NHSDigital/DTOSS-11313-validation-exception
DTOSS-11313: Log to Insights if validation fails on create_message_status
2 parents 1c2fd01 + 9ff510c commit cf29366

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

manage_breast_screening/notifications/tests/test_views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_create_message_status_with_valid_request():
5454
queue_instance.add.assert_called_once_with(json.dumps(body))
5555

5656

57-
def test_create_message_status_with_invalid_request():
57+
def test_create_message_status_with_invalid_request(mock_insights_logger):
5858
req = RequestFactory().post(
5959
"/notifications/message-status/create",
6060
{"some": "data"},
@@ -68,3 +68,7 @@ def test_create_message_status_with_invalid_request():
6868

6969
assert response.status_code == expected_response.status_code
7070
assert response.text == expected_response.text
71+
72+
mock_insights_logger.assert_called_once_with(
73+
"Request validation failed: Signature does not match"
74+
)

manage_breast_screening/notifications/views.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
31
from django.contrib.auth.decorators import login_not_required
42
from django.http import JsonResponse
53
from django.views.decorators.csrf import csrf_exempt
@@ -8,6 +6,9 @@
86
from manage_breast_screening.core.decorators import (
97
basic_auth_exempt,
108
)
9+
from manage_breast_screening.notifications.services.application_insights_logging import (
10+
ApplicationInsightsLogging,
11+
)
1112
from manage_breast_screening.notifications.services.queue import Queue
1213
from manage_breast_screening.notifications.validators.request_validator import (
1314
RequestValidator,
@@ -22,7 +23,9 @@ def create_message_status(request):
2223
valid, message = RequestValidator(request).valid()
2324

2425
if not valid:
25-
logging.error("Request validation failed: %s", message)
26+
ApplicationInsightsLogging().exception(
27+
(f"Request validation failed: {message}")
28+
)
2629
return JsonResponse({"error": {"message": message}}, status=400)
2730

2831
Queue.MessageStatusUpdates().add(request.body.decode("ASCII"))

0 commit comments

Comments
 (0)