Skip to content

Commit 908c1f7

Browse files
VED-242: Updated error messaging when search requests exceed 1MB limit (#1448)
* VED-242: Updated error messaging when search requests exceed 1MB limit * Rename MAX_SEARCH_RESPONSE_SIZE_BYTES constant
1 parent cef7e32 commit 908c1f7

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

lambdas/backend/src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient."
44
# Maximum response size for an AWS Lambda function
5-
MAX_RESPONSE_SIZE_BYTES = 6 * 1024 * 1024
5+
MAX_SEARCH_RESPONSE_SIZE_BYTES = 1 * 1024 * 1024

lambdas/backend/src/controller/fhir_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fhir.resources.R4B.identifier import Identifier
1212

1313
from common.get_service_url import get_service_url
14-
from constants import MAX_RESPONSE_SIZE_BYTES
14+
from constants import MAX_SEARCH_RESPONSE_SIZE_BYTES
1515
from controller.aws_apig_event_utils import (
1616
get_multi_value_query_params,
1717
get_path_parameter,
@@ -213,7 +213,7 @@ def _search_immunizations_by_target_disease(self, search_params: dict[str, list[
213213
def _create_search_response(self, search_bundle: Bundle) -> dict:
214214
search_response_json = search_bundle.json(use_decimal=True)
215215

216-
if len(search_response_json) > MAX_RESPONSE_SIZE_BYTES:
216+
if len(search_response_json) > MAX_SEARCH_RESPONSE_SIZE_BYTES:
217217
raise TooManyResultsError("Search returned too many results. Please narrow down the search")
218218

219219
prepared_search_bundle = self._prepare_search_bundle(search_response_json)

lambdas/backend/tests/controller/test_fhir_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ def test_search_immunizations_returns_a_validation_error_when_optional_params_in
12071207
)
12081208
self.service.search_immunizations.assert_not_called()
12091209

1210-
@patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5)
1210+
@patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5)
12111211
def test_search_immunizations_raises_error_if_too_many_results_found(self):
12121212
"""it should return an error if there are too many results in the response for Lambda to handle. In reality,
12131213
highly unlikely. If a concern, pagination should be implemented."""

lambdas/backend/tests/controller/test_fhir_controller_target_disease.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def test_search_by_target_disease_with_mixed_valid_and_invalid_returns_200_with_
288288
self.assertIn("invalid-no-pipe", call_args[1]["invalid_target_diseases"][0])
289289
self.assertIn("Invalid format", call_args[1]["invalid_target_diseases"][0])
290290

291-
@patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5)
291+
@patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5)
292292
def test_search_by_target_disease_returns_400_when_response_too_large(self):
293293
"""it should return the same narrow-the-search error for oversized target-disease searches"""
294294
self.mock_redis.hget.side_effect = self._hget_target_disease_codes_and_mmr

0 commit comments

Comments
 (0)