diff --git a/ds-caselaw-ingester/lambda_function.py b/ds-caselaw-ingester/lambda_function.py index 0d5ab49..9425c05 100644 --- a/ds-caselaw-ingester/lambda_function.py +++ b/ds-caselaw-ingester/lambda_function.py @@ -94,6 +94,9 @@ def save_s3_response(self, sqs_client, s3_client): out.close() return filename + + def validate(self): + return class V2Message(Message): @@ -119,6 +122,11 @@ def save_s3_response(self, sqs_client, s3_client): raise RuntimeError(f"File {filename} not created") print(f"tar.gz saved locally as {filename}") return filename + + def validate(self): + message_type = self.message["properties"]["messageType"] + if message_type != "uk.gov.nationalarchives.tre.messages.courtdocumentpackage.available.CourtDocumentPackageAvailable": + raise WrongMessageTypeError(f"Received message with type: {message_type}") class ReportableException(Exception): @@ -126,6 +134,9 @@ def __init__(self, *args, **kwargs): rollbar.report_message("Something happened!", "warning", str(self)) super().__init__(*args, **kwargs) +class WrongMessageTypeError(ReportableException): + pass + class S3HTTPError(ReportableException): pass @@ -413,6 +424,8 @@ def unpublish_updated_judgment(uri): def handler(event, context): message = Message.from_event(event) + message.validate() + consignment_reference = message.get_consignment_reference() print(f"Ingester Start: Consignment reference {consignment_reference}") print(f"Received Message: {message.message}")