Skip to content

Commit

Permalink
fix(HTTPHandler): do not parse body if value is None
Browse files Browse the repository at this point in the history
  • Loading branch information
sleistner committed Nov 5, 2020
1 parent 13f4fc7 commit bd4402b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lambda_handlers/handlers/http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions lambda_handlers/handlers/tests/test_http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bd4402b

Please sign in to comment.