hyperping 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
+ """Hyperping API client exceptions.
2
+
3
+ All exceptions carry optional ``status_code``, ``response_body``, and
4
+ ``request_id`` fields for diagnostic context.
5
+ """
6
+
7
+ from typing import Any
8
+
9
+
10
+ class HyperpingAPIError(Exception):
11
+ """Base exception for Hyperping API errors.
12
+
13
+ Args:
14
+ message: Human-readable error description.
15
+ status_code: HTTP status code, if the error originated from an HTTP response.
16
+ response_body: Parsed JSON body of the error response, if available.
17
+ request_id: Server-assigned request identifier (``x-request-id`` header),
18
+ if the server included one.
19
+ """
20
+
21
+ def __init__(
22
+ self,
23
+ message: str,
24
+ status_code: int | None = None,
25
+ response_body: dict[str, Any] | None = None,
26
+ request_id: str | None = None,
27
+ ) -> None:
28
+ super().__init__(message)
29
+ self.message = message
30
+ self.status_code = status_code
31
+ self.response_body = response_body or {}
32
+ self.request_id = request_id
33
+
34
+ def __str__(self) -> str:
35
+ if self.status_code:
36
+ return f"[{self.status_code}] {self.message}"
37
+ return self.message
38
+
39
+
40
+ class HyperpingAuthError(HyperpingAPIError):
41
+ """Raised when authentication fails (HTTP 401 or 403)."""
42
+
43
+ pass
44
+
45
+
46
+ class HyperpingNotFoundError(HyperpingAPIError):
47
+ """Raised when a resource is not found (HTTP 404)."""
48
+
49
+ pass
50
+
51
+
52
+ class HyperpingRateLimitError(HyperpingAPIError):
53
+ """Raised when the API rate limit is exceeded (HTTP 429).
54
+
55
+ Args:
56
+ message: Human-readable error description.
57
+ retry_after: Seconds to wait before retrying, from the ``Retry-After``
58
+ response header. ``None`` if the header was absent.
59
+ **kwargs: Forwarded to :class:`HyperpingAPIError`.
60
+ """
61
+
62
+ def __init__(
63
+ self,
64
+ message: str,
65
+ retry_after: int | None = None,
66
+ **kwargs: Any,
67
+ ) -> None:
68
+ super().__init__(message, **kwargs)
69
+ self.retry_after = retry_after
70
+
71
+
72
+ class HyperpingValidationError(HyperpingAPIError):
73
+ """Raised when request validation fails (HTTP 400 or 422).
74
+
75
+ Args:
76
+ message: Human-readable error description.
77
+ validation_errors: Structured validation error details from the API
78
+ response body (``details`` or ``errors`` key).
79
+ **kwargs: Forwarded to :class:`HyperpingAPIError`.
80
+ """
81
+
82
+ def __init__(
83
+ self,
84
+ message: str,
85
+ validation_errors: list[dict[str, Any]] | None = None,
86
+ **kwargs: Any,
87
+ ) -> None:
88
+ super().__init__(message, **kwargs)
89
+ self.validation_errors = validation_errors or []