Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 37 additions & 41 deletions lambdas/enums/lambda_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,32 +492,66 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
"fhir_coding": UKCoreSpineError.ACCESS_DENIED,
}
"""
Errors for document review lambda
Errors for document review lambdas
"""
DocumentReviewNotFound = {
"err_code": "DRV_4041",
"message": "Document review not found",
"fhir_coding": UKCoreSpineError.RESOURCE_NOT_FOUND,
}

DocumentReviewGeneralError = {
"err_code": "DRV_4002",
"message": "An error occurred while fetching the document review",
"fhir_coding": FhirIssueCoding.EXCEPTION,
}

UpdateDocStatusUnavailable = {
"err_code": "DRV_4003",
"err_code": "UDR_4001",
"message": "This Document is not available for review update",
"fhir_coding": FhirIssueCoding.FORBIDDEN,
}

DocumentReviewInvalidBody = {
"err_code": "DRV_4004",
"message": "Invalid request body",
}

DocumentReviewInvalidNhsNumber = {
"err_code": "DRV_4005",
"message": "The NHS number provided is invalid",
}

DocumentReviewDB = {
"err_code": "UDR_5001",
"message": RETRIEVE_DOCUMENTS,
}

DocumentReviewValidation = {
"err_code": "UDR_5002",
"message": "Review document model error",
}

DocumentReviewMissingODS = {
"err_code": "DRV_4001",
"message": "Missing ODS code in request context",
}

SearchDocumentInvalidQuerystring = {
"err_code": "SDR_4002",
"message": "Invalid query string passed",
}

DocumentReviewUploadForbidden = {
"err_code": "UDR_4031",
"message": "Forbidden"
}

DocumentReviewPresignedFailure = {
"err_code": "UDR_5003",
"message": "Presign creation process failure",
}

"""
Errors for get ods report lambda
"""
Expand Down Expand Up @@ -660,42 +694,4 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str:
"err_code": "UE_500",
"message": "An internal server error occurred",
"fhir_coding": FhirIssueCoding.EXCEPTION,
}

"""
Errors for DocumentReview exceptions
"""
DocumentReviewDB = {
"err_code": "UDR_5001",
"message": RETRIEVE_DOCUMENTS,
}

DocumentReviewValidation = {
"err_code": "UDR_5002",
"message": "Review document model error",
}

DocumentReviewMissingODS = {
"err_code": "UDR_4001",
"message": "Missing ODS code in request context",
}

SearchDocumentInvalidQuerystring = {
"err_code": "SDR_4002",
"message": "Invalid query string passed",
}

DocumentReviewUploadInvalidRequest = {
"err_code": "UDR_4003",
"message": "Invalid request",
}

DocumentReviewUploadForbidden = {
"err_code": "UDR_4031",
"message": "Forbidden"
}

DocumentReviewPresignedFailure = {
"err_code": "UDR_5003",
"message": "Presign creation process failure",
}
}
4 changes: 2 additions & 2 deletions lambdas/handlers/get_document_review_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from utils.decorators.override_error_check import override_error_check
from utils.decorators.set_audit_arg import set_request_context_for_logging
from utils.decorators.validate_patient_id import validate_patient_id
from utils.lambda_exceptions import GetDocumentReviewException
from utils.lambda_exceptions import DocumentReviewLambdaException
from utils.lambda_handler_utils import validate_review_path_parameters
from utils.lambda_response import ApiGatewayResponse
from utils.request_context import request_context
Expand Down Expand Up @@ -45,7 +45,7 @@ def lambda_handler(event, context):

if not patient_id:
logger.error("Missing patient_id in query string parameters")
raise GetDocumentReviewException(
raise DocumentReviewLambdaException(
400, LambdaError.DocumentReferenceMissingParameters
)

Expand Down
4 changes: 2 additions & 2 deletions lambdas/handlers/post_document_review_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def lambda_handler(event, context):
except KeyError as e:
logger.error(e)
raise DocumentReviewLambdaException(
400, LambdaError.DocumentReviewUploadInvalidRequest
400, LambdaError.DocumentReviewInvalidBody
)

post_document_review_service = PostDocumentReviewService()
Expand All @@ -58,5 +58,5 @@ def validate_event_body(body):
except (ValidationError, InvalidNhsNumberException) as e:
logger.error(e)
raise DocumentReviewLambdaException(
400, LambdaError.DocumentReviewUploadInvalidRequest
400, LambdaError.DocumentReviewInvalidBody
)
6 changes: 3 additions & 3 deletions lambdas/services/get_document_review_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from services.document_upload_review_service import DocumentUploadReviewService
from utils.audit_logging_setup import LoggingService
from utils.exceptions import DynamoServiceException
from utils.lambda_exceptions import GetDocumentReviewException
from utils.lambda_exceptions import DocumentReviewLambdaException
from utils.utilities import format_cloudfront_url

logger = LoggingService(__name__)
Expand Down Expand Up @@ -87,13 +87,13 @@ def get_document_review(
f"{LambdaError.DocRefClient.to_str()}: {str(e)}",
{"Result": "Failed to retrieve document review"},
)
raise GetDocumentReviewException(500, LambdaError.DocRefClient)
raise DocumentReviewLambdaException(500, LambdaError.DocRefClient)
except Exception as e:
logger.error(
f"Unexpected error retrieving document review: {str(e)}",
{"Result": "Failed to retrieve document review"},
)
raise GetDocumentReviewException(500, LambdaError.DocRefClient)
raise DocumentReviewLambdaException(500, LambdaError.DocRefClient)

def create_cloudfront_presigned_url(self, file_location: str) -> str:
"""Create a CloudFront obfuscated pre-signed URL for a file.
Expand Down
2 changes: 1 addition & 1 deletion lambdas/services/post_document_review_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process_event(self, event: DocumentReviewUploadEvent) -> dict:
)
except PatientNotFoundException:
raise DocumentReviewLambdaException(
400, LambdaError.DocumentReviewUploadInvalidRequest
400, LambdaError.DocumentReviewInvalidBody
)
except ValidationError:
raise DocumentReviewLambdaException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from enums.lambda_error import LambdaError
from handlers.get_document_review_handler import lambda_handler
from utils.lambda_exceptions import GetDocumentReviewException
from utils.lambda_exceptions import DocumentReviewLambdaException
from utils.lambda_response import ApiGatewayResponse

MOCK_DOCUMENT_REVIEW_RESPONSE = {
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_lambda_handler_raises_exception_returns_500(
context,
mock_upload_document_iteration_3_enabled,
):
mocked_service.get_document_review.side_effect = GetDocumentReviewException(
mocked_service.get_document_review.side_effect = DocumentReviewLambdaException(
500, LambdaError.MockError
)
actual = lambda_handler(valid_get_document_review_event, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def test_lambda_handler_returns_400_invalid_event(
invalid_event, context, mock_upload_document_iteration_3_enabled, set_env
):
body = {
"message": LambdaError.DocumentReviewUploadInvalidRequest.value["message"],
"err_code": LambdaError.DocumentReviewUploadInvalidRequest.value["err_code"],
"message": LambdaError.DocumentReviewInvalidBody.value["message"],
"err_code": LambdaError.DocumentReviewInvalidBody.value["err_code"],
"interaction_id": MOCK_INTERACTION_ID,
}

Expand All @@ -167,8 +167,8 @@ def test_lambda_handler_returns_400_no_body_in_event(
invalid_event_missing_body, context, mock_upload_document_iteration_3_enabled, set_env
):
body = {
"message": LambdaError.DocumentReviewUploadInvalidRequest.value["message"],
"err_code": LambdaError.DocumentReviewUploadInvalidRequest.value["err_code"],
"message": LambdaError.DocumentReviewInvalidBody.value["message"],
"err_code": LambdaError.DocumentReviewInvalidBody.value["err_code"],
"interaction_id": MOCK_INTERACTION_ID,
}

Expand Down Expand Up @@ -198,7 +198,7 @@ def test_validate_event_body_invalid_event_throws_error(invalid_event):
with pytest.raises(DocumentReviewLambdaException) as e:
validate_event_body(json.loads(invalid_event["body"]))
assert e.value.status_code == 400
assert e.value.err_code == "UDR_4003"
assert e.value.err_code == "DRV_4004"


def test_validate_event_body_valid_event_returns_document_review_upload_event_model(
Expand All @@ -219,7 +219,7 @@ def test_validate_event_body_throws_error_unsupported_snomed_code(invalid_event)
with pytest.raises(DocumentReviewLambdaException) as e:
validate_event_body(invalid_event["body"])
assert e.value.status_code == 400
assert e.value.err_code == "UDR_4003"
assert e.value.err_code == "DRV_4004"


def test_lambda_handler_calls_service_with_validated_event(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
TEST_NHS_NUMBER,
)
from utils.exceptions import DynamoServiceException
from utils.lambda_exceptions import GetDocumentReviewException
from utils.lambda_exceptions import DocumentReviewLambdaException

TEST_DOCUMENT_ID = "test-document-id-123"
TEST_DOCUMENT_VERSION = 1
Expand Down Expand Up @@ -169,37 +169,35 @@ def test_get_document_review_nhs_number_mismatch(mock_service, mock_document_rev


def test_get_document_review_dynamo_service_exception(mock_service):
"""Test handling of DynamoServiceException."""
mock_service.document_review_service.get_document_review_by_id.side_effect = (
DynamoServiceException("DynamoDB error")
)

with pytest.raises(GetDocumentReviewException) as exc_info:
with pytest.raises(DocumentReviewLambdaException) as e:
mock_service.get_document_review(
patient_id=TEST_NHS_NUMBER,
document_id=TEST_DOCUMENT_ID,
document_version=TEST_DOCUMENT_VERSION,
)

assert exc_info.value.status_code == 500
assert exc_info.value.error == LambdaError.DocRefClient
assert e.value.status_code == 500
assert e.value.error == LambdaError.DocRefClient


def test_get_document_review_unexpected_exception(mock_service):
"""Test handling of unexpected exceptions."""
mock_service.document_review_service.get_document_review_by_id.side_effect = (
Exception("Unexpected error")
)

with pytest.raises(GetDocumentReviewException) as exc_info:
with pytest.raises(DocumentReviewLambdaException) as e:
mock_service.get_document_review(
patient_id=TEST_NHS_NUMBER,
document_id=TEST_DOCUMENT_ID,
document_version=TEST_DOCUMENT_VERSION,
)

assert exc_info.value.status_code == 500
assert exc_info.value.error == LambdaError.DocRefClient
assert e.value.status_code == 500
assert e.value.error == LambdaError.DocRefClient


@freeze_time("2023-11-03T12:00:00Z")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_process_event_throws_error_failure_to_extract_ods_from_request_context(
mock_service.process_event(VALID_EVENT)

assert e.value.status_code == 400
assert e.value.err_code == "UDR_4001"
assert e.value.err_code == "DRV_4001"


def test_process_event_calls_pds_for_patient_status_with_nhs_number(
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_process_event_handles_pds_patient_not_found(mock_service, mock_extract_
mock_service.process_event(VALID_EVENT)

assert e.value.status_code == 400
assert e.value.err_code == "UDR_4003"
assert e.value.err_code == "DRV_4004"


def test_process_event_handles_client_error(mock_service, mock_extract_ods):
Expand Down
16 changes: 0 additions & 16 deletions lambdas/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,5 @@ class SSHKeyManagementException(Exception):
pass


class ReviewProcessVerifyingException(Exception):
pass


class ReviewProcessMovingException(Exception):
pass


class ReviewProcessDeleteException(Exception):
pass


class ReviewProcessCreateRecordException(Exception):
pass


class CorruptedFileException(Exception):
pass
4 changes: 0 additions & 4 deletions lambdas/utils/lambda_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,5 @@ class DocumentReviewLambdaException(LambdaException):
pass


class GetDocumentReviewException(LambdaException):
pass


class UpdateDocumentReviewException(LambdaException):
pass
Loading