Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update decorator to handle invalid/empty json body.
----------------------------------------------- This commit refactors the request body handling in the validate_request decorator. Previously, the code attempted to access request.json directly, which could raise a "Failed to decode JSON object" error when the request body was empty or contained invalid JSON. To address this issue, the code has been updated to use a try-except block. It now checks request.is_json and handles two scenarios: - If request.is_json is True, indicating a JSON content type, it tries to access request.json to retrieve the JSON payload. If the request body contains invalid JSON, the WerkzeugBadRequest exception is caught, and the body is set to an empty dictionary. - If request.is_json is False or request.json raises an error for any reason, body is also set to an empty dictionary.
- Loading branch information