asockslib 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ """Custom exceptions for the ASocks library.
2
+
3
+ Exception hierarchy::
4
+
5
+ ASocksError (base)
6
+ ├── AuthenticationError # HTTP 401/403
7
+ ├── RateLimitError # HTTP 429
8
+ ├── PortNotFoundError # HTTP 404
9
+ ├── InsufficientBalanceError # HTTP 402
10
+ ├── APIConnectionError # network/transport failure (timeout, refused)
11
+ ├── ProxyHealthError # proxy health-check failure
12
+ └── NoAvailableProxyError # proxy pool exhausted
13
+
14
+ All exceptions inherit from :class:`ASocksError`, allowing a single
15
+ ``except`` block to catch every library error.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+
21
+ class ASocksError(Exception):
22
+ """Base exception for all ASocks errors.
23
+
24
+ Attributes:
25
+ message: Human-readable error description.
26
+ status_code: HTTP status code returned by the API, if applicable.
27
+
28
+ Example::
29
+
30
+ try:
31
+ await client.get_balance()
32
+ except ASocksError as e:
33
+ print(f"Error [{e.status_code}]: {e.message}")
34
+ """
35
+
36
+ def __init__(self, message: str, status_code: int | None = None) -> None:
37
+ self.message = message
38
+ self.status_code = status_code
39
+ super().__init__(self.message)
40
+
41
+
42
+ class AuthenticationError(ASocksError):
43
+ """Invalid or missing API key (HTTP 401/403)."""
44
+
45
+
46
+ class RateLimitError(ASocksError):
47
+ """API rate limit exceeded (HTTP 429).
48
+
49
+ The client retries automatically with exponential back-off
50
+ (up to 5 attempts). This exception is raised only after all
51
+ retries are exhausted.
52
+ """
53
+
54
+
55
+ class PortNotFoundError(ASocksError):
56
+ """Requested port does not exist (HTTP 404)."""
57
+
58
+
59
+ class InsufficientBalanceError(ASocksError):
60
+ """Insufficient account balance (HTTP 402).
61
+
62
+ Top up your balance at https://my.asocks.com.
63
+ """
64
+
65
+
66
+ class APIConnectionError(ASocksError):
67
+ """Network/transport failure talking to the ASocks API.
68
+
69
+ Raised when the HTTP request cannot complete — connection refused,
70
+ connection reset, DNS failure, or timeout — after all retries are
71
+ exhausted. Wraps the underlying ``httpx.TransportError`` (available
72
+ via ``__cause__``) so callers get a single typed error to catch.
73
+ """
74
+
75
+
76
+ class ProxyHealthError(ASocksError):
77
+ """Proxy failed a health check.
78
+
79
+ Raised by :class:`SmartProxy` when a proxy is unreachable,
80
+ times out, or returns an unexpected response.
81
+ """
82
+
83
+
84
+ class NoAvailableProxyError(ASocksError):
85
+ """No proxies matching the requested criteria are available.
86
+
87
+ Raised by :class:`SmartProxy` / :class:`ProxyPool` when the
88
+ pool is empty or all proxies have failed health checks.
89
+ """