From 3fd733994fa15fbac20cd2ce1b378bb2d1163711 Mon Sep 17 00:00:00 2001 From: ariagraham-nhs Date: Tue, 28 Apr 2026 16:20:50 +0100 Subject: [PATCH 1/2] VED-242: Updated error messaging when search requests exceed 1MB limit --- lambdas/backend/src/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambdas/backend/src/constants.py b/lambdas/backend/src/constants.py index 3e571191ae..24d5d812de 100644 --- a/lambdas/backend/src/constants.py +++ b/lambdas/backend/src/constants.py @@ -2,4 +2,4 @@ GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient." # Maximum response size for an AWS Lambda function -MAX_RESPONSE_SIZE_BYTES = 6 * 1024 * 1024 +MAX_RESPONSE_SIZE_BYTES = 1 * 1024 * 1024 From e58051ee8471fc8652db2948bcb0bdcb8436be21 Mon Sep 17 00:00:00 2001 From: ariagraham-nhs Date: Wed, 29 Apr 2026 15:30:09 +0100 Subject: [PATCH 2/2] Rename MAX_SEARCH_RESPONSE_SIZE_BYTES constant --- lambdas/backend/src/constants.py | 2 +- lambdas/backend/src/controller/fhir_controller.py | 4 ++-- lambdas/backend/tests/controller/test_fhir_controller.py | 2 +- .../tests/controller/test_fhir_controller_target_disease.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lambdas/backend/src/constants.py b/lambdas/backend/src/constants.py index 24d5d812de..d6aa8c6e2e 100644 --- a/lambdas/backend/src/constants.py +++ b/lambdas/backend/src/constants.py @@ -2,4 +2,4 @@ GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient." # Maximum response size for an AWS Lambda function -MAX_RESPONSE_SIZE_BYTES = 1 * 1024 * 1024 +MAX_SEARCH_RESPONSE_SIZE_BYTES = 1 * 1024 * 1024 diff --git a/lambdas/backend/src/controller/fhir_controller.py b/lambdas/backend/src/controller/fhir_controller.py index dda8986698..6d271a2abc 100644 --- a/lambdas/backend/src/controller/fhir_controller.py +++ b/lambdas/backend/src/controller/fhir_controller.py @@ -11,7 +11,7 @@ from fhir.resources.R4B.identifier import Identifier from common.get_service_url import get_service_url -from constants import MAX_RESPONSE_SIZE_BYTES +from constants import MAX_SEARCH_RESPONSE_SIZE_BYTES from controller.aws_apig_event_utils import ( get_multi_value_query_params, get_path_parameter, @@ -213,7 +213,7 @@ def _search_immunizations_by_target_disease(self, search_params: dict[str, list[ def _create_search_response(self, search_bundle: Bundle) -> dict: search_response_json = search_bundle.json(use_decimal=True) - if len(search_response_json) > MAX_RESPONSE_SIZE_BYTES: + if len(search_response_json) > MAX_SEARCH_RESPONSE_SIZE_BYTES: raise TooManyResultsError("Search returned too many results. Please narrow down the search") prepared_search_bundle = self._prepare_search_bundle(search_response_json) diff --git a/lambdas/backend/tests/controller/test_fhir_controller.py b/lambdas/backend/tests/controller/test_fhir_controller.py index e8afb79905..72cff2af7e 100644 --- a/lambdas/backend/tests/controller/test_fhir_controller.py +++ b/lambdas/backend/tests/controller/test_fhir_controller.py @@ -1207,7 +1207,7 @@ def test_search_immunizations_returns_a_validation_error_when_optional_params_in ) self.service.search_immunizations.assert_not_called() - @patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5) + @patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5) def test_search_immunizations_raises_error_if_too_many_results_found(self): """it should return an error if there are too many results in the response for Lambda to handle. In reality, highly unlikely. If a concern, pagination should be implemented.""" diff --git a/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py b/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py index d9e62b39c9..dce6cbef62 100644 --- a/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py +++ b/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py @@ -288,7 +288,7 @@ def test_search_by_target_disease_with_mixed_valid_and_invalid_returns_200_with_ self.assertIn("invalid-no-pipe", call_args[1]["invalid_target_diseases"][0]) self.assertIn("Invalid format", call_args[1]["invalid_target_diseases"][0]) - @patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5) + @patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5) def test_search_by_target_disease_returns_400_when_response_too_large(self): """it should return the same narrow-the-search error for oversized target-disease searches""" self.mock_redis.hget.side_effect = self._hget_target_disease_codes_and_mmr