Skip to content

Implement unified response parser #12

@codebestia

Description

@codebestia

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions