fix: raise RateLimitError when 429 retries are exhausted

RateLimitError was defined and exported but could never be raised.
When all retry attempts are exhausted on a 429 response, _parse_response
now raises RateLimitError instead of a generic StackAuthError. Callers
writing `except RateLimitError` will now correctly catch rate limit
failures.
This commit is contained in:
Ejiro Asiuwhu 2026-03-26 11:19:01 +01:00
parent a6ac1889e1
commit 94293c14bd

View File

@ -17,7 +17,7 @@ import httpx
from stack_auth._constants import API_VERSION, DEFAULT_BASE_URL, SDK_NAME
from stack_auth._version import __version__
from stack_auth.errors import StackAuthError
from stack_auth.errors import RateLimitError, StackAuthError
HttpxClientT = TypeVar("HttpxClientT", httpx.Client, httpx.AsyncClient)
@ -116,6 +116,10 @@ class BaseAPIClient(Generic[HttpxClientT]):
return actual_status, response.json()
return actual_status, None
# Rate limit (429 that exhausted retries)
if actual_status == 429:
raise RateLimitError(code="RATE_LIMIT_EXCEEDED", message="Rate limit exceeded after retries")
# Unrecognised error
raise StackAuthError(code="HTTP_ERROR", message=f"HTTP {actual_status}")