-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: REST Event Handler doesn't handle some json parsing exceptions #3672
Comments
Hi @Dilski! Thanks for opening this potential bug. I'm working to reproduce this error and will update this issue as soon as I have an update. |
@leandrodamascena just for extra info, we were doing this with a private API gateway and so tested with test invoke on the console |
This was the missing piece of this puzzle! I could not reproduce this either in my local environment or on the Swagger/Public/Private endpoint. However, using the APIGW "Test" on the console I was able to reproduce it. This is a very specific bug and thanks a lot for catching and reporting this. Testing your APIs thought AWS Console it will send to Lambda the exact string you added in the Headers section, and in this case the string is: "headers": {
"Content-Type": " application/json"
},
"multiValueHeaders": {
"Content-Type": [
" application/json"
]
}, If you see, there is a space before the We are planning to release a version on February 8th. Please let me know if it is enough for you to wait until then or need this fix immediately. Thanks. |
|
This is now released under 2.33.0 version! |
Expected Behaviour
This may or may not be a bug, but the REST API event handler payload validator does not gracefully handle empty bodies. I would expect an empty body to raise a 4xx (maybe a 422)
Current Behaviour
With the following setup, invoking the
POST /todos
endpoint withcontent-type: application/json
but with an empty body will raise aTypeError
and return a 500 error.Code snippet
Possible Solution
powertools-lambda-python/aws_lambda_powertools/event_handler/middlewares/openapi_validation.py
Line 218 in e1ca584
The validation middleware handles a
json.JSONDecodeError
exception, butjson.loads
will raise aTypeError
if the request body is empty.We could either:
TypeError
and raise an appropriate responseNone
in_get_body
Steps to Reproduce
Invoke the REST endpoint with an empty body.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: