-
Notifications
You must be signed in to change notification settings - Fork 5
Handle JSON Decoder errors #762
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
Handle JSON Decoder errors #762
Conversation
In the event that a request is malformed JSON, we want to handle this issue gracefully and return a 400
WalkthroughThis set of changes enforces strict JSON request validation for API endpoints, particularly for provider registration. The code now rejects requests with unsupported media types and malformed JSON, returning appropriate HTTP error responses (415 for unsupported media type, 400 for malformed JSON). A new exception class is introduced to represent unsupported media types, and the schema for provider registration is made strict by switching its base class. Unit tests and test resources are updated to verify and reflect the new validation logic, while some code is reformatted for clarity. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API Gateway
participant Lambda(api_handler)
participant Schema
Client->>API Gateway: POST /v1/provider-users/registration (with headers/body)
API Gateway->>Lambda(api_handler): Invoke with event
Lambda(api_handler)->>Lambda(api_handler): Check Content-Type header
alt Content-Type is not application/json
Lambda(api_handler)-->>Client: Return 415 Unsupported Media Type
else Content-Type is application/json
Lambda(api_handler)->>Lambda(api_handler): Parse JSON body
alt Malformed JSON
Lambda(api_handler)-->>Client: Return 400 Bad Request
else Well-formed JSON
Lambda(api_handler)->>Schema: Validate and load body
alt Validation error
Lambda(api_handler)-->>Client: Return 400 Bad Request
else Valid
Lambda(api_handler)-->>Client: Return 200 OK (or relevant response)
end
end
end
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Graph Analysis (2)backend/compact-connect/lambdas/python/common/cc_common/utils.py (1)
backend/compact-connect/lambdas/python/common/tests/unit/test_api_handler.py (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (8)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This will prevent callers from setting invalid media types when calling the registration endpoint.
2842dd8
to
bb5d1c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@landonshumway-ia , you want to review my contribution here, as well?
@jusdino looks good. @jlkravitz This is ready for your review. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! @isabeleliassen Good to merge.
In the event that a request is malformed JSON, we want to handle this issue gracefully and return a 400
This also sets the registration endpoint request schema to strict, to avoid allowing the user to specify any unrecognized fields.
Closes #761
Summary by CodeRabbit