|
1 | 1 | from typing import Any, Dict |
2 | | -from niquests import Response |
3 | 2 | from .routes.models import ActionAttempt |
4 | 3 |
|
5 | 4 |
|
6 | 5 | # HTTP |
7 | 6 | class SeamHttpApiError(Exception): |
| 7 | + """ |
| 8 | + Base exception for Seam HTTP API errors. |
| 9 | +
|
| 10 | + This exception encapsulates details about HTTP errors returned by the Seam API, |
| 11 | + including the error message, error code, HTTP status code, request ID, and any |
| 12 | + additional error data. |
| 13 | +
|
| 14 | + :ivar code: The error type returned by the API |
| 15 | + :vartype code: str |
| 16 | + :ivar status_code: The HTTP status code of the error response |
| 17 | + :vartype status_code: int |
| 18 | + :ivar request_id: The unique identifier for the API request |
| 19 | + :vartype request_id: str |
| 20 | + :ivar data: Additional error data, if provided by the API |
| 21 | + :vartype data: Dict[str, Any] |
| 22 | + """ |
| 23 | + |
8 | 24 | def __init__(self, error: Dict[str, Any], status_code: int, request_id: str): |
9 | | - super().__init__(error["message"]) |
10 | | - self.code = error["type"] |
| 25 | + """ |
| 26 | + :param error: Dictionary containing error details from the API response |
| 27 | + :type error: Dict[str, Any] |
| 28 | + :param status_code: HTTP status code of the error response |
| 29 | + :type status_code: int |
| 30 | + :param request_id: Unique identifier for the API request |
| 31 | + :type request_id: str |
| 32 | + """ |
| 33 | + |
| 34 | + super().__init__(error.get("message")) |
| 35 | + self.code = error.get("type") |
11 | 36 | self.status_code = status_code |
12 | 37 | self.request_id = request_id |
13 | 38 | self.data = error.get("data") |
14 | 39 |
|
15 | 40 |
|
16 | 41 | class SeamHttpUnauthorizedError(SeamHttpApiError): |
| 42 | + """ |
| 43 | + Exception raised when the API request is unauthorized. |
| 44 | +
|
| 45 | + This exception is a specific type of SeamHttpApiError for 401 Unauthorized errors. |
| 46 | + """ |
| 47 | + |
17 | 48 | def __init__(self, request_id: str): |
| 49 | + """ |
| 50 | + :param request_id: Unique identifier for the API request |
| 51 | + :type request_id: str |
| 52 | + """ |
| 53 | + |
18 | 54 | super().__init__( |
19 | 55 | {"type": "unauthorized", "message": "Unauthorized"}, 401, request_id |
20 | 56 | ) |
21 | 57 |
|
22 | 58 |
|
23 | 59 | class SeamHttpInvalidInputError(SeamHttpApiError): |
| 60 | + """ |
| 61 | + Exception raised when the API request contains invalid input params. |
| 62 | +
|
| 63 | + This exception is a specific type of SeamHttpApiError for invalid input param errors. |
| 64 | +
|
| 65 | + :ivar code: "invalid_input" error type |
| 66 | + :vartype code: str |
| 67 | + """ |
| 68 | + |
24 | 69 | def __init__(self, error: Dict[str, Any], status_code: int, request_id: str): |
| 70 | + """ |
| 71 | + :param error: Dictionary containing error details from the API response |
| 72 | + :type error: Dict[str, Any] |
| 73 | + :param status_code: HTTP status code of the error response |
| 74 | + :type status_code: int |
| 75 | + :param request_id: Unique identifier for the API request |
| 76 | + :type request_id: str |
| 77 | + """ |
| 78 | + |
25 | 79 | super().__init__(error, status_code, request_id) |
26 | 80 | self.code = "invalid_input" |
27 | 81 |
|
28 | 82 |
|
29 | 83 | # Action Attempt |
30 | 84 | class SeamActionAttemptError(Exception): |
| 85 | + """ |
| 86 | + Base exception for Seam Action Attempt errors. |
| 87 | +
|
| 88 | + :ivar name: Name of the exception class |
| 89 | + :vartype name: str |
| 90 | + :ivar action_attempt: The ActionAttempt object associated with this error |
| 91 | + :vartype action_attempt: ActionAttempt |
| 92 | + """ |
| 93 | + |
31 | 94 | def __init__(self, message: str, action_attempt: ActionAttempt): |
| 95 | + """ |
| 96 | + :param message: Error message |
| 97 | + :type message: str |
| 98 | + :param action_attempt: The ActionAttempt object associated with this error |
| 99 | + :type action_attempt: ActionAttempt |
| 100 | + """ |
| 101 | + |
32 | 102 | super().__init__(message) |
33 | 103 | self.name = self.__class__.__name__ |
34 | 104 | self.action_attempt = action_attempt |
35 | 105 |
|
36 | 106 |
|
37 | 107 | class SeamActionAttemptFailedError(SeamActionAttemptError): |
| 108 | + """ |
| 109 | + Exception raised when a Seam Action Attempt fails. |
| 110 | +
|
| 111 | + :ivar name: Name of the exception class |
| 112 | + :vartype name: str |
| 113 | + :ivar code: The error type from the action attempt |
| 114 | + :vartype code: str |
| 115 | + """ |
| 116 | + |
38 | 117 | def __init__(self, action_attempt: ActionAttempt): |
| 118 | + """ |
| 119 | + :param action_attempt: The ActionAttempt object associated with this error |
| 120 | + :type action_attempt: ActionAttempt |
| 121 | + """ |
| 122 | + |
39 | 123 | super().__init__(action_attempt.error.message, action_attempt) |
40 | 124 | self.name = self.__class__.__name__ |
41 | 125 | self.code = action_attempt.error.type |
42 | 126 |
|
43 | 127 |
|
44 | 128 | class SeamActionAttemptTimeoutError(SeamActionAttemptError): |
| 129 | + """ |
| 130 | + Exception raised when a Seam Action Attempt times out while waiting for the action attempt to reach a resolved state. |
| 131 | +
|
| 132 | + This error occurs when the system has waited for the specified timeout period, but the action |
| 133 | + attempt has not reached either a success or failed state within that time. |
| 134 | +
|
| 135 | + :ivar name: Name of the exception class |
| 136 | + :vartype name: str |
| 137 | + """ |
| 138 | + |
45 | 139 | def __init__(self, action_attempt: ActionAttempt, timeout: str): |
| 140 | + """ |
| 141 | + :param action_attempt: The ActionAttempt object associated with this error |
| 142 | + :type action_attempt: ActionAttempt |
| 143 | + :param timeout: The timeout duration in seconds |
| 144 | + :type timeout: str |
| 145 | + """ |
| 146 | + |
46 | 147 | message = f"Timed out waiting for action attempt after {timeout}s" |
47 | 148 | super().__init__(message, action_attempt) |
48 | 149 | self.name = self.__class__.__name__ |
0 commit comments