diff --git a/lambdas/enums/lambda_error.py b/lambdas/enums/lambda_error.py index 5c8f47b48..270cb5798 100644 --- a/lambdas/enums/lambda_error.py +++ b/lambdas/enums/lambda_error.py @@ -497,27 +497,31 @@ 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", @@ -527,6 +531,36 @@ def create_error_body(self, params: Optional[dict] = None, **kwargs) -> str: "message": "The file type provided is not supported", } + DocumentReviewDB = { + "err_code": "UDR_5001", + "message": ErrorMessage.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 """ @@ -669,39 +703,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": ErrorMessage.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", - } + } \ No newline at end of file diff --git a/lambdas/handlers/get_document_review_handler.py b/lambdas/handlers/get_document_review_handler.py index b90f174de..30b8becfc 100644 --- a/lambdas/handlers/get_document_review_handler.py +++ b/lambdas/handlers/get_document_review_handler.py @@ -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 @@ -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 ) diff --git a/lambdas/handlers/post_document_review_handler.py b/lambdas/handlers/post_document_review_handler.py index eef9add02..40e1d334b 100644 --- a/lambdas/handlers/post_document_review_handler.py +++ b/lambdas/handlers/post_document_review_handler.py @@ -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() @@ -58,7 +58,7 @@ def validate_event_body(body): except (ValidationError, InvalidNhsNumberException) as e: logger.error(e) raise DocumentReviewLambdaException( - 400, LambdaError.DocumentReviewUploadInvalidRequest + 400, LambdaError.DocumentReviewInvalidBody ) except InvalidFileTypeException as e: logger.error(e) diff --git a/lambdas/services/get_document_review_service.py b/lambdas/services/get_document_review_service.py index 204b6765d..93ff9462b 100644 --- a/lambdas/services/get_document_review_service.py +++ b/lambdas/services/get_document_review_service.py @@ -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__) @@ -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. diff --git a/lambdas/services/post_document_review_service.py b/lambdas/services/post_document_review_service.py index 859890df2..317b00524 100644 --- a/lambdas/services/post_document_review_service.py +++ b/lambdas/services/post_document_review_service.py @@ -76,7 +76,7 @@ def process_event(self, event: DocumentReviewUploadEvent) -> dict: ) except PatientNotFoundException: raise DocumentReviewLambdaException( - 400, LambdaError.DocumentReviewUploadInvalidRequest + 400, LambdaError.DocumentReviewInvalidBody ) except ValidationError: raise DocumentReviewLambdaException( diff --git a/lambdas/tests/unit/handlers/test_get_document_review_handler.py b/lambdas/tests/unit/handlers/test_get_document_review_handler.py index 5516bcea3..9a93e058e 100644 --- a/lambdas/tests/unit/handlers/test_get_document_review_handler.py +++ b/lambdas/tests/unit/handlers/test_get_document_review_handler.py @@ -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 = { @@ -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) diff --git a/lambdas/tests/unit/handlers/test_post_document_review_handler.py b/lambdas/tests/unit/handlers/test_post_document_review_handler.py index 715bbae49..b5ccfc40c 100644 --- a/lambdas/tests/unit/handlers/test_post_document_review_handler.py +++ b/lambdas/tests/unit/handlers/test_post_document_review_handler.py @@ -155,8 +155,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, } @@ -173,8 +173,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, } @@ -204,7 +204,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( @@ -225,7 +225,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_validate_event_body_throws_error_unsupported_file_type(invalid_event): diff --git a/lambdas/tests/unit/services/test_get_document_review_service.py b/lambdas/tests/unit/services/test_get_document_review_service.py index 330b7eb70..0d2dcadb8 100644 --- a/lambdas/tests/unit/services/test_get_document_review_service.py +++ b/lambdas/tests/unit/services/test_get_document_review_service.py @@ -17,7 +17,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 @@ -170,37 +170,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") diff --git a/lambdas/tests/unit/services/test_post_document_review_service.py b/lambdas/tests/unit/services/test_post_document_review_service.py index 8576b4a76..d2223e40f 100644 --- a/lambdas/tests/unit/services/test_post_document_review_service.py +++ b/lambdas/tests/unit/services/test_post_document_review_service.py @@ -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( @@ -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): diff --git a/lambdas/utils/exceptions.py b/lambdas/utils/exceptions.py index d22e35e4a..ca0c95f37 100644 --- a/lambdas/utils/exceptions.py +++ b/lambdas/utils/exceptions.py @@ -176,34 +176,6 @@ class TransactionConflictException(Exception): pass -class ReviewProcessVerifyingException(Exception): - pass - - -class ReviewProcessMovingException(Exception): - pass - - -class ReviewProcessDeleteException(Exception): - pass - - -class ReviewProcessCreateRecordException(Exception): - pass - - -class SSHKeyManagementException(Exception): - pass - - -class CorruptedFileException(Exception): - pass - - -class InvalidFileTypeException(Exception): - pass - - class MigrationUnrecoverableException(Exception): def __init__(self, message: str, item_id: str): super().__init__(message) @@ -222,3 +194,14 @@ def __init__(self, message: str, segment_id: str): def to_dict(self): return {"segmentId": self.segment_id, "message": self.message} + + +class SSHKeyManagementException(Exception): + pass + + +class CorruptedFileException(Exception): + pass + +class InvalidFileTypeException(Exception): + pass diff --git a/lambdas/utils/lambda_exceptions.py b/lambdas/utils/lambda_exceptions.py index fd7a3dff9..77934baf5 100644 --- a/lambdas/utils/lambda_exceptions.py +++ b/lambdas/utils/lambda_exceptions.py @@ -113,9 +113,5 @@ class DocumentReviewLambdaException(LambdaException): pass -class GetDocumentReviewException(LambdaException): - pass - - class UpdateDocumentReviewException(LambdaException): pass