Skip to content

Commit 09e6a21

Browse files
committed
Update comment, check if code is bool, and use logger instead of print
Signed-off-by: Phillippe Siclait <[email protected]>
1 parent 1696311 commit 09e6a21

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/bindings/python/rust/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ where
160160
if let Some(py_err) = e.downcast_ref::<PyErr>() {
161161
Python::with_gil(|py| {
162162
// With the Stable ABI, we can't subclass Python's built-in exceptions in PyO3, so instead we
163-
// implement the exception in Python and use duck typing / assume that it's an HttpError if
164-
// the code and message are present.
163+
// implement the exception in Python and assume that it's an HttpError if the code and message
164+
// are present.
165165
if let Ok(HttpError { code, message }) =
166166
py_err.value(py).extract::<HttpError>()
167167
{

lib/bindings/python/src/dynamo/llm/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33

44
# flake8: noqa
55

6+
import logging
7+
8+
logger = logging.getLogger(__name__)
9+
610
_MAX_MESSAGE_LENGTH = 8192
711

812

913
class HttpError(Exception):
1014
def __init__(self, code: int, message: str):
1115
# These ValueErrors are easier to trace to here than the TypeErrors that
1216
# would be raised otherwise.
13-
if not isinstance(code, int):
17+
if not isinstance(code, int) or isinstance(code, bool):
1418
raise ValueError("HttpError status code must be an integer")
1519

1620
if not isinstance(message, str):
@@ -20,7 +24,7 @@ def __init__(self, code: int, message: str):
2024
raise ValueError("HTTP status code must be an integer between 0 and 599")
2125

2226
if len(message) > _MAX_MESSAGE_LENGTH:
23-
print(
27+
logger.warning(
2428
f"HttpError message length {len(message)} exceeds max length {_MAX_MESSAGE_LENGTH}, truncating..."
2529
)
2630
message = message[: (_MAX_MESSAGE_LENGTH - 3)] + "..."

0 commit comments

Comments
 (0)