Skip to content

Commit 0ee4ab2

Browse files
author
SentienceDEV
committed
include network error
1 parent f19b349 commit 0ee4ab2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

sentience/backends/snapshot.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ async def _snapshot_via_api(
621621
# Re-raise validation errors as-is
622622
raise
623623
except Exception as e:
624+
# Preserve structured gateway details when available.
625+
try:
626+
from ..snapshot import SnapshotGatewayError # type: ignore
627+
628+
if isinstance(e, SnapshotGatewayError):
629+
raise
630+
except Exception:
631+
pass
632+
624633
# Fallback to local extension on API error
625634
# This matches the behavior of the main snapshot function
626635
raise RuntimeError(

sentience/snapshot.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def from_httpx(cls, e: Exception) -> "SnapshotGatewayError":
9696
body_snip = cls._snip(body)
9797
if body_snip:
9898
bits.append(f"body={body_snip}")
99+
# If we don't have an HTTP status/response body, this is usually a transport error
100+
# (timeout, DNS, connection reset). Preserve at least the exception type + message.
101+
if status_code is None and not body_snip:
102+
try:
103+
err_s = cls._snip(str(e), 220)
104+
except Exception:
105+
err_s = None
106+
bits.append(f"err_type={type(e).__name__}")
107+
if err_s:
108+
bits.append(f"err={err_s}")
99109
if bits:
100110
msg = f"{msg}: " + " ".join(bits)
101111
msg = msg + ". Try using use_api=False to use local extension instead."
@@ -144,6 +154,14 @@ def from_requests(cls, e: Exception) -> "SnapshotGatewayError":
144154
body_snip = cls._snip(body)
145155
if body_snip:
146156
bits.append(f"body={body_snip}")
157+
if status_code is None and not body_snip:
158+
try:
159+
err_s = cls._snip(str(e), 220)
160+
except Exception:
161+
err_s = None
162+
bits.append(f"err_type={type(e).__name__}")
163+
if err_s:
164+
bits.append(f"err={err_s}")
147165
if bits:
148166
msg = f"{msg}: " + " ".join(bits)
149167
msg = msg + ". Try using use_api=False to use local extension instead."

0 commit comments

Comments
 (0)