Skip to content

Commit 05df251

Browse files
author
alex-omophub
committed
Add retry logic for server errors in SyncHTTPClient and AsyncHTTPClientImpl
- Implemented retry mechanism for handling server errors (502, 503, 504) in both synchronous and asynchronous HTTP clients. - Added exponential backoff delay for retries to improve resilience against temporary server issues.
1 parent 3d3f3a2 commit 05df251

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/omophub/_http.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ def request(
137137
params=filtered_params if filtered_params else None,
138138
json=json,
139139
)
140+
# Retry on server errors (502, 503, 504)
141+
if response.status_code in (502, 503, 504) and attempt < self._max_retries:
142+
time.sleep(2**attempt * 0.5)
143+
continue
140144
return response.content, response.status_code, response.headers
141145

142146
except httpx.ConnectError as e:
@@ -222,6 +226,10 @@ async def request(
222226
params=filtered_params if filtered_params else None,
223227
json=json,
224228
)
229+
# Retry on server errors (502, 503, 504)
230+
if response.status_code in (502, 503, 504) and attempt < self._max_retries:
231+
await asyncio.sleep(2**attempt * 0.5)
232+
continue
225233
return response.content, response.status_code, response.headers
226234

227235
except httpx.ConnectError as e:

0 commit comments

Comments
 (0)