"""Retry predicate for transient HTTP errors."""

from __future__ import annotations

import httpx


def is_retryable(exc: Exception) -> bool:
    """Return True for transient errors worth retrying.

    Retries: HTTP 429 (rate limit), 5xx (server errors),
    connection errors, timeouts.
    Does NOT retry: 4xx client errors (permanent failures).
    """
    if isinstance(exc, httpx.HTTPStatusError):
        code = exc.response.status_code
        return code == 429 or code >= 500
    return isinstance(
        exc,
        (httpx.ConnectError, httpx.TimeoutException),
    )


# https://smee.io/ACAUooTvHulETive
