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

Do not retry in case of an nginx timeout error #35

Merged
merged 1 commit into from
Oct 25, 2024
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
24 changes: 13 additions & 11 deletions upstash_vector/http.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import asyncio
import os
import time
import asyncio
from platform import python_version
from typing import Any, Dict

from httpx import Client, AsyncClient
from platform import python_version

from upstash_vector import __version__
from upstash_vector.errors import UpstashError
Expand Down Expand Up @@ -41,7 +42,7 @@ def execute_with_parameters(

for attempts_left in range(max(0, retries), -1, -1):
try:
response = client.post(url=url, headers=headers, json=payload).json()
response = client.post(url=url, headers=headers, json=payload)
break

except Exception as e:
Expand All @@ -53,10 +54,11 @@ def execute_with_parameters(
assert last_error is not None
raise last_error

if "error" in response:
raise UpstashError(response["error"])
body = response.json()
if "error" in body:
raise UpstashError(body["error"])

return response["result"]
return body["result"]


async def execute_with_parameters_async(
Expand All @@ -72,8 +74,7 @@ async def execute_with_parameters_async(

for attempts_left in range(max(0, retries), -1, -1):
try:
resp = await client.post(url=url, headers=headers, json=payload)
response = resp.json()
response = await client.post(url=url, headers=headers, json=payload)
break

except Exception as e:
Expand All @@ -85,7 +86,8 @@ async def execute_with_parameters_async(
assert last_error is not None
raise last_error

if "error" in response:
raise UpstashError(response["error"])
body = response.json()
if "error" in body:
raise UpstashError(body["error"])

return response["result"]
return body["result"]
Loading