diff --git a/lambda_handlers/handlers/http_handler.py b/lambda_handlers/handlers/http_handler.py index 27f20342..b2aee2b4 100644 --- a/lambda_handlers/handlers/http_handler.py +++ b/lambda_handlers/handlers/http_handler.py @@ -54,7 +54,7 @@ def on_exception(self, exception): def format_input(self, event): """Return `event` with a formatted `event['body']`.""" - if 'body' in event: + if 'body' in event and event['body']: try: event['body'] = self._input_format.format(event['body']) except FormatError as error: diff --git a/lambda_handlers/handlers/tests/test_http_handler.py b/lambda_handlers/handlers/tests/test_http_handler.py index c9e03c57..b3bf06a8 100644 --- a/lambda_handlers/handlers/tests/test_http_handler.py +++ b/lambda_handlers/handlers/tests/test_http_handler.py @@ -20,6 +20,11 @@ def test_empty_body_validation(self, handler): assert isinstance(response, dict) assert response['statusCode'] == 200 + def test_none_body_validation(self, handler): + response = handler({'body': None}, None) + assert isinstance(response, dict) + assert response['statusCode'] == 200 + def test_invalid_body_validation(self, handler): response = handler({'body': '{.x'}, None) assert isinstance(response, dict)