Skip to content

Commit

Permalink
Merge pull request #145 from enter-at/fix/http-handler/handle-none-bo…
Browse files Browse the repository at this point in the history
…dy-values-gracefully

fix(HTTPHandler): do not parse body if value is  None
  • Loading branch information
sleistner authored Nov 5, 2020
2 parents 35b4481 + bd4402b commit 6f3d7c0
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 6f3d7c0

Please sign in to comment.