Implement InvalidRequestError with field-level validation details#26
Open
samueloyibodevv wants to merge 1 commit into
Open
Conversation
Add param and field_errors parsing from API error responses and raise InvalidRequestError on HTTP 400/422 so developers can identify bad params.
Contributor
|
Hello @samueloyibodevv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements
InvalidRequestErrorin 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
src/shade/errors.pyInvalidRequestError(ShadeError)withparam: Optional[str]andfield_errors: dict.{"error": {"code": "invalid_param", "param": "amount", "message": "..."}}.InvalidRequestError.from_response()to construct the exception from raw 400/422 response bodies.raise_for_invalid_request()to raiseInvalidRequestErroron HTTP 400 and 422 responses.__str__()so the offending parameter name is included in the error message when available.🧪 Tests
tests/test_errors.pyparamfrom API error responses.field_errorsfrom API error responses.str(error)includes the param name.InvalidRequestError.Verification Results
InvalidRequestErrorerror.paramnames the offending field when the API provides oneerror.field_errorscontains all field-level errors from the API responsestr(error)includes the param name in the message