Skip to content

Commit 6f3d7c0

Browse files
authored
Merge pull request #145 from enter-at/fix/http-handler/handle-none-body-values-gracefully
fix(HTTPHandler): do not parse body if value is None
2 parents 35b4481 + bd4402b commit 6f3d7c0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lambda_handlers/handlers/http_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def on_exception(self, exception):
5454

5555
def format_input(self, event):
5656
"""Return `event` with a formatted `event['body']`."""
57-
if 'body' in event:
57+
if 'body' in event and event['body']:
5858
try:
5959
event['body'] = self._input_format.format(event['body'])
6060
except FormatError as error:

lambda_handlers/handlers/tests/test_http_handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ def test_empty_body_validation(self, handler):
2020
assert isinstance(response, dict)
2121
assert response['statusCode'] == 200
2222

23+
def test_none_body_validation(self, handler):
24+
response = handler({'body': None}, None)
25+
assert isinstance(response, dict)
26+
assert response['statusCode'] == 200
27+
2328
def test_invalid_body_validation(self, handler):
2429
response = handler({'body': '{.x'}, None)
2530
assert isinstance(response, dict)

0 commit comments

Comments
 (0)