Description
All resource methods should go through a single _parse_response(response) function that handles JSON decoding, success detection, and mapping HTTP error codes to the correct typed exceptions. This prevents per-resource error handling drift.
Proposed Steps
- Create
_parse_response(response: httpx.Response) -> dict in http_client.py.
- On 2xx: decode JSON and return the dict.
- On 401: raise
AuthenticationError.
- On 400 / 422: raise
InvalidRequestError with field-level errors if present.
- On 404: raise
NotFoundError.
- On 429: raise
RateLimitError.
- On 5xx: raise
NetworkError (subject to retry).
- On JSON decode failure: raise
ShadeError("Invalid response from API").
Acceptance Criteria
- Every 4xx/5xx response is mapped to the correct exception type.
- The raw response body and HTTP status are accessible on every exception.
- A non-JSON response body raises
ShadeError rather than crashing with a raw JSONDecodeError.
- 2xx responses that contain an
error key in the body are still treated as errors.
Description
All resource methods should go through a single
_parse_response(response)function that handles JSON decoding, success detection, and mapping HTTP error codes to the correct typed exceptions. This prevents per-resource error handling drift.Proposed Steps
_parse_response(response: httpx.Response) -> dictinhttp_client.py.AuthenticationError.InvalidRequestErrorwith field-level errors if present.NotFoundError.RateLimitError.NetworkError(subject to retry).ShadeError("Invalid response from API").Acceptance Criteria
ShadeErrorrather than crashing with a rawJSONDecodeError.errorkey in the body are still treated as errors.