Skip to content

Commit

Permalink
Merge pull request #170 from uktrade/add-logging
Browse files Browse the repository at this point in the history
Add logging for failures to ingest licence data
  • Loading branch information
kevincarrogan authored Oct 31, 2022
2 parents 106a192 + e4a1f35 commit 661eb35
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ def post(self, request):
data = request.data["licence"]
except KeyError:
errors = [{"licence": "This field is required."}]

logger.error(
"Failed to create licence data for %s due to %s",
request.data,
errors,
)
return JsonResponse(status=status.HTTP_400_BAD_REQUEST, data={"errors": errors})

serializer_cls = self.get_serializer_cls(data["type"])
serializer = serializer_cls(data=data)

if not serializer.is_valid():
errors = [{"licence": serializer.errors}]
logger.error(
"Failed to create licence data for %s due to %s",
data,
errors,
)
return JsonResponse(status=status.HTTP_400_BAD_REQUEST, data={"errors": errors})

if data["action"] == LicenceActionEnum.UPDATE:
Expand Down

0 comments on commit 661eb35

Please sign in to comment.