Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry http bad status #15

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions gator/common/http_api.py
Original file line number Diff line number Diff line change
@@ -56,15 +56,15 @@ async def get(self, route: str) -> Dict[str, str]:
full_url = f"http://{self.url}{self.ROUTE_PREFIX}/{route}"
for _ in range(self.retries):
try:
async with self.session.get(full_url) as resp:
async with self.session.get(full_url, raise_for_status=True) as resp:
data = await resp.json()
if data.get("result", None) != "success":
print(
f"Failed to GET from route '{route}' via '{self.url}'",
file=sys.stderr,
)
return data
except aiohttp.ClientConnectionError:
except (aiohttp.ClientConnectionError, aiohttp.ClientResponseError):
await asyncio.sleep(self.delay)
else:
print(
@@ -89,15 +89,17 @@ async def post(self, route: str, **kwargs: Any) -> Dict[str, str]:
full_url = f"http://{self.url}{self.ROUTE_PREFIX}/{route}"
for _ in range(10):
try:
async with self.session.post(full_url, json=kwargs) as resp:
async with self.session.post(
full_url, json=kwargs, raise_for_status=True
) as resp:
data = await resp.json()
if data.get("result", None) != "success":
print(
f"Failed to POST to route '{route}' via '{self.url}'",
file=sys.stderr,
)
return data
except aiohttp.ClientConnectionError:
except (aiohttp.ClientConnectionError, aiohttp.ClientResponseError):
await asyncio.sleep(0.1)
else:
print(