Skip to content

feat: implement exceptions and error handling#101

Open
Stasky745 wants to merge 2 commits into
mainfrom
feature/sre-10558/return-request-response-code
Open

feat: implement exceptions and error handling#101
Stasky745 wants to merge 2 commits into
mainfrom
feature/sre-10558/return-request-response-code

Conversation

@Stasky745

@Stasky745 Stasky745 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Solves #99

What changed

The SDK was silently discarding HTTP response metadata — callers received only the JSON body and had no way to access the status code or detect errors. A 404 or 500 response would be returned as a plain dict, indistinguishable from a successful response.

Core fix

Added response.raise_for_status() in ApiClient.request() before returning. This single change means any 4xx or 5xx response now raises requests.HTTPError instead of being silently passed through. The exception carries the full response, so callers can still inspect the status code and error body when needed:

try:
    client.subscribers.get(id)
except requests.HTTPError as e:
    print(e.response.status_code)
    print(e.response.json())

SDK method cleanup

With errors now handled centrally, all manual status code checks across the SDK were simplified:

  • Methods that returned True if response.status_code == 204 else False now just return True — the False branch is unreachable since a non-204 raises before it
  • subscribers.delete() and subscribers.forget() were returning raw status code integers (204, 200) — changed to return True for consistency

Test updates

  • "Returns False on not found" assertions converted to pytest.raises(requests.HTTPError) — this is what actually happens now, and it's the correct behaviour
  • Status code integer assertions (== 204, == 200) updated to is True

Bonus fix

Removed a stray print(query_params) debug statement left in automations.list().

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.

1 participant