Skip to content

Implement InvalidRequestError with field-level validation details#26

Open
samueloyibodevv wants to merge 1 commit into
ShadeProtocol:mainfrom
samueloyibodevv:fix/17-implement-invalid-request-error
Open

Implement InvalidRequestError with field-level validation details#26
samueloyibodevv wants to merge 1 commit into
ShadeProtocol:mainfrom
samueloyibodevv:fix/17-implement-invalid-request-error

Conversation

@samueloyibodevv

Copy link
Copy Markdown

Overview

This PR implements InvalidRequestError in the Shade Python SDK so developers get clear, field-level feedback when the API rejects malformed or invalid request parameters. It parses the API error response format, exposes the offending field and all field errors, and raises the exception on HTTP 400/422 responses.

Related Issue

Closes #17

Changes

⚠️ Invalid Request Error Handling

  • [MODIFY] src/shade/errors.py
  • Expanded InvalidRequestError(ShadeError) with param: Optional[str] and field_errors: dict.
  • Added parsing for API error responses such as {"error": {"code": "invalid_param", "param": "amount", "message": "..."}}.
  • Added InvalidRequestError.from_response() to construct the exception from raw 400/422 response bodies.
  • Added raise_for_invalid_request() to raise InvalidRequestError on HTTP 400 and 422 responses.
  • Updated __str__() so the offending parameter name is included in the error message when available.

🧪 Tests

  • [MODIFY] tests/test_errors.py
  • Added tests for parsing param from API error responses.
  • Added tests for parsing field_errors from API error responses.
  • Added tests verifying str(error) includes the param name.
  • Added tests verifying HTTP 400 and 422 responses raise InvalidRequestError.
  • Added tests verifying explicit constructor arguments override parsed body values.
  • Added tests verifying non-400/422 status codes do not raise.

Verification Results

pytest tests/test_errors.py tests/test_gateway.py -v ✅ passed (13/13)
Acceptance Criteria Status
A 400 response raises InvalidRequestError
error.param names the offending field when the API provides one
error.field_errors contains all field-level errors from the API response
str(error) includes the param name in the message

Add param and field_errors parsing from API error responses and raise
InvalidRequestError on HTTP 400/422 so developers can identify bad params.
@codebestia

Copy link
Copy Markdown
Contributor

Hello @samueloyibodevv
Please resolve the conflicts.

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.

Implement InvalidRequestError

2 participants