Skip to content

Commit 4037707

Browse files
Add docstrings to error classes (#134)
* Safely access error type and message in SeamHttpApiError * Document SeamHttpApiError * Document SeamHttpUnauthorizedError * Document SeamHttpInvalidInputError * Document SeamActionAttemptError * Document SeamActionAttemptFailedError * Document SeamActionAttemptTimeoutError * Move param dosctrings to constructor methods * Add vartypes to error docstrings * Document SeamInvalidOptionsError * Document SeamInvalidTokenError * Fix SeamInvalidOptionsError docstring
1 parent 733aa97 commit 4037707

3 files changed

Lines changed: 132 additions & 3 deletions

File tree

seam/auth.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@
1616

1717

1818
class SeamInvalidTokenError(Exception):
19+
"""
20+
Exception raised when an invalid token is provided to the Seam client.
21+
22+
This error occurs when a token of incorrect type or format is used for
23+
authentication. It can be raised in various scenarios, such as using a
24+
client session token as an API key, or providing a token with an incorrect
25+
prefix.
26+
"""
27+
1928
def __init__(self, message):
29+
"""
30+
:param message: Detailed description of the invalid token
31+
:type message: str
32+
"""
33+
2034
super().__init__(f"Seam received an invalid token: {message}")
2135

2236

seam/exceptions.py

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,149 @@
11
from typing import Any, Dict
2-
from niquests import Response
32
from .routes.models import ActionAttempt
43

54

65
# HTTP
76
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+
824
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")
1136
self.status_code = status_code
1237
self.request_id = request_id
1338
self.data = error.get("data")
1439

1540

1641
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+
1748
def __init__(self, request_id: str):
49+
"""
50+
:param request_id: Unique identifier for the API request
51+
:type request_id: str
52+
"""
53+
1854
super().__init__(
1955
{"type": "unauthorized", "message": "Unauthorized"}, 401, request_id
2056
)
2157

2258

2359
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+
2469
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+
2579
super().__init__(error, status_code, request_id)
2680
self.code = "invalid_input"
2781

2882

2983
# Action Attempt
3084
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+
3194
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+
32102
super().__init__(message)
33103
self.name = self.__class__.__name__
34104
self.action_attempt = action_attempt
35105

36106

37107
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+
38117
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+
39123
super().__init__(action_attempt.error.message, action_attempt)
40124
self.name = self.__class__.__name__
41125
self.code = action_attempt.error.type
42126

43127

44128
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+
45139
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+
46147
message = f"Timed out waiting for action attempt after {timeout}s"
47148
super().__init__(message, action_attempt)
48149
self.name = self.__class__.__name__

seam/options.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@ def get_endpoint_from_env():
3232

3333

3434
class SeamInvalidOptionsError(Exception):
35+
"""
36+
Exception raised when invalid options are provided to Seam client.
37+
38+
This error occurs when incompatible or incomplete options are provided
39+
when initializing or using Seam client components, such as using both API key
40+
and personal access token simultaneously, or using a personal access token
41+
without specifying a workspace ID.
42+
"""
43+
3544
def __init__(self, message):
45+
"""
46+
:param message: Detailed description of the invalid option
47+
:type message: str
48+
"""
49+
3650
super().__init__(f"Seam received invalid options: {message}")
3751

3852

0 commit comments

Comments
 (0)