Exceptions
Custom exceptions for the ASocks library.
Exception hierarchy::
ASocksError (base) ├── AuthenticationError # HTTP 401/403 ├── RateLimitError # HTTP 429 ├── PortNotFoundError # HTTP 404 ├── InsufficientBalanceError # HTTP 402 ├── APIConnectionError # network/transport failure (timeout, refused) ├── ProxyHealthError # proxy health-check failure └── NoAvailableProxyError # proxy pool exhausted
All exceptions inherit from :class:ASocksError, allowing a single
except block to catch every library error.
APIConnectionError
Section titled “APIConnectionError”Network/transport failure talking to the ASocks API.
Raised when the HTTP request cannot complete — connection refused,
connection reset, DNS failure, or timeout — after all retries are
exhausted. Wraps the underlying httpx.TransportError (available
via __cause__) so callers get a single typed error to catch.
ASocksError
Section titled “ASocksError”Base exception for all ASocks errors.
Attributes: message: Human-readable error description. status_code: HTTP status code returned by the API, if applicable.
Example::
try: await client.get_balance() except ASocksError as e: print(f”Error [{e.status_code}]: {e.message}“)
AuthenticationError
Section titled “AuthenticationError”Invalid or missing API key (HTTP 401/403).
InsufficientBalanceError
Section titled “InsufficientBalanceError”Insufficient account balance (HTTP 402).
Top up your balance at https://my.asocks.com.
NoAvailableProxyError
Section titled “NoAvailableProxyError”No proxies matching the requested criteria are available.
Raised by :class:SmartProxy / :class:ProxyPool when the
pool is empty or all proxies have failed health checks.
PortNotFoundError
Section titled “PortNotFoundError”Requested port does not exist (HTTP 404).
ProxyHealthError
Section titled “ProxyHealthError”Proxy failed a health check.
Raised by :class:SmartProxy when a proxy is unreachable,
times out, or returns an unexpected response.
RateLimitError
Section titled “RateLimitError”API rate limit exceeded (HTTP 429).
The client retries automatically with exponential back-off (up to 5 attempts). This exception is raised only after all retries are exhausted.