-
Notifications
You must be signed in to change notification settings - Fork 450
Description
Heya All,
Not sure if this would be seen as an issue or not, but I thought I would log it anyways. When using the APIGatewayProxyEvent.json_body function I have found that if there is no body, it will throw a TypeError:
[ERROR] TypeError: the JSON object must be str, bytes or bytearray, not NoneType
I feel on the fence whether it's better to validate that there is a body before attempting to json_body but I guess with the return type hint being Any I was maybe expecting a None or empty string.
Expected Behavior
I expect the json_body should return an empty string if the object is not present in the payload
Current Behavior
Function throws a TypeError because json.loads cannot handle None objects.
Steps to Reproduce (for bugs)
app = ApiGatewayResolver()
@app.get("/test")
def get_test():
app.current_event.json_body
def handler(event: dict, context: dict) -> dict:
return app.resolve(event=event, context=context)
Including a REST request with an None body.
Again, not sure if this should be considered a bug or not, looking for guidance here, is a minor issue.
Environment
- Powertools version used: 1.22.0
- Packaging format (Layers, PyPi): Layers
- AWS Lambda function runtime: Python 3.9
- Debugging logs