Skip to content

Commit

Permalink
py: Retry on 408 (#1075)
Browse files Browse the repository at this point in the history
- 408 is "client took too long to send request body"
  • Loading branch information
nfcampos authored Oct 8, 2024
2 parents 0d46af7 + 2342ffb commit f034c38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def request_with_retries(
*(retry_on or ()),
*(
ls_utils.LangSmithConnectionError,
ls_utils.LangSmithRequestTimeout,
ls_utils.LangSmithAPIError,
),
)
Expand Down Expand Up @@ -870,6 +871,11 @@ def request_with_retries(
f" LangSmith API. {repr(e)}"
f"{_context}"
)
elif response.status_code == 408:
raise ls_utils.LangSmithRequestTimeout(
f"Client took too long to send request to {method}"
f"{pathname} {_context}"
)
elif response.status_code == 429:
raise ls_utils.LangSmithRateLimitError(
f"Rate limit exceeded for {pathname}. {repr(e)}"
Expand Down
4 changes: 4 additions & 0 deletions python/langsmith/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class LangSmithAPIError(LangSmithError):
"""Internal server error while communicating with LangSmith."""


class LangSmithRequestTimeout(LangSmithError):
"""Client took too long to send request body."""


class LangSmithUserError(LangSmithError):
"""User error caused an exception when communicating with LangSmith."""

Expand Down

0 comments on commit f034c38

Please sign in to comment.