Skip to content

Commit 021ef45

Browse files
committed
Refactor error handling in HTTPClient and AsyncHTTPClient to provide clearer rate limit messages and maintain exception context
1 parent 64d8a7e commit 021ef45

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

recallrai/utils/async_http_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async def request(
173173
http_status=response.status_code
174174
)
175175
elif response.status_code == 429:
176-
detail = response.json().get("detail", "Please try again in a few moments.")
176+
detail = "429 Too Many Requests. Please try again in a few moments."
177177
raise RateLimitError(
178178
message=detail,
179179
http_status=response.status_code
@@ -187,12 +187,12 @@ async def request(
187187
raise TimeoutError(
188188
message=f"Request timed out: {e}",
189189
http_status=0 # No HTTP status for timeout
190-
)
190+
) from e
191191
except (ConnectError, JSONDecodeError) as e:
192192
raise ConnectionError(
193193
message=f"Failed to connect to the API: {e}",
194194
http_status=0 # No HTTP status for connection error
195-
)
195+
) from e
196196
except Exception as e:
197197
# Handle other exceptions as needed
198198
raise e

recallrai/utils/http_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def request(
138138
http_status=response.status_code
139139
)
140140
elif response.status_code == 429:
141-
detail = response.json().get("detail", "Please try again in a few moments.")
141+
detail = "429 Too Many Requests. Please try again in a few moments."
142142
raise RateLimitError(
143143
message=detail,
144144
http_status=response.status_code
@@ -152,12 +152,12 @@ def request(
152152
raise TimeoutError(
153153
message=f"Request timed out: {e}",
154154
http_status=0 # No HTTP status for timeout
155-
)
155+
) from e
156156
except (ConnectError, JSONDecodeError) as e:
157157
raise ConnectionError(
158158
message=f"Failed to connect to the API: {e}",
159159
http_status=0 # No HTTP status for connection error
160-
)
160+
) from e
161161
except Exception as e:
162162
# Handle other exceptions as needed
163163
raise e

0 commit comments

Comments
 (0)