Skip to content

Fix: Add null check and error handling for JSON parsing in /decode endpoint#92

Open
prjanitor wants to merge 1 commit intoAryanNanda17:masterfrom
prjanitor:prjanitor/37a545fab5d0d411c8e14753802486d866354cbf
Open

Fix: Add null check and error handling for JSON parsing in /decode endpoint#92
prjanitor wants to merge 1 commit intoAryanNanda17:masterfrom
prjanitor:prjanitor/37a545fab5d0d411c8e14753802486d866354cbf

Conversation

@prjanitor
Copy link
Copy Markdown

Summary

This PR fixes a bug in the /decode endpoint where json.loads() was called directly on the input parameter without checking if it was None or empty. This caused the server to crash with a TypeError or JSONDecodeError when the 'input' query parameter was missing or empty.

Changes

  • Added null/empty check for the input parameter before JSON parsing
  • Wrapped json.loads() in a try-except block to catch JSONDecodeError
  • Returns appropriate 400 error responses with descriptive error messages

Testing

The endpoint now properly handles:

  • Missing 'input' parameter → Returns 400 with error message
  • Empty 'input' parameter → Returns 400 with error message
  • Invalid JSON → Returns 400 with error message
  • Valid JSON → Processes normally

This PR was generated by PRJanitor — an automated tool that finds and fixes small bugs in open-source projects.

We respect your contribution guidelines — if your project doesn't accept bot PRs, we won't send more. You can also add a .github/prjanitor.yml file with enabled: false to opt out explicitly.

Add validation to check if 'input' parameter is None or empty before calling json.loads(). Also wrap JSON parsing in try-except to handle invalid JSON gracefully with appropriate error responses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant