Skip to content

Commit 134a50c

Browse files
committed
Merge branch 'mr/forestier/fix-flask-wrapper' into 'master'
Avoid exception from not modified status code response See merge request it/e3-aws!60
2 parents 4463931 + 3a2c73a commit 134a50c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/e3/aws/troposphere/awslambda/flask_apigateway_wrapper.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ def lambda_handler(self, event: dict, context: dict) -> FlaskLambdaResponse:
5454
"""Lambda entry point."""
5555
self.status = None
5656
self.response_headers = None
57-
58-
body = next(
59-
self.app.wsgi_app(
60-
self.create_flask_wsgi_environ(event, context), self.start_response
57+
try:
58+
body = next(
59+
self.app.wsgi_app(
60+
self.create_flask_wsgi_environ(event, context), self.start_response
61+
)
6162
)
62-
)
63+
except StopIteration:
64+
# Flask can return empty body. It can happen for static files that are
65+
# automatically added to a view. For instance, if the status code is 304
66+
# (Not Modified) there is no response body.
67+
print("wsgi_app does not return a response body")
68+
body = ""
6369

6470
returndict: FlaskLambdaResponse = {
6571
"statusCode": cast(int, self.status),

0 commit comments

Comments
 (0)