Skip to content

Commit 507a4f5

Browse files
authored
fix(sdk): preserve unavailable error details (#4534)
Co-authored-by: hylin <linhongyu510@users.noreply.github.com>
1 parent ae50736 commit 507a4f5

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

sdk/python/openviking_sdk/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ def _raise_exception(self, error: Dict[str, Any]) -> None:
662662
resource = details.get("resource", "") if details else ""
663663
resource_type = details.get("type", "resource") if details else "resource"
664664
raise exc_class(resource, resource_type)
665+
if exc_class == UnavailableError:
666+
service = details.get("service", "service") if details else "service"
667+
reason = details.get("reason", "") if details else message
668+
raise exc_class(service, reason)
665669
raise exc_class(message)
666670

667671
def _zip_directory(self, dir_path: str) -> str:

sdk/python/tests/test_error_mapping.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ConflictError,
66
OpenVikingError,
77
ResourceExhaustedError,
8+
UnavailableError,
89
UnimplementedError,
910
)
1011

@@ -41,3 +42,27 @@ def test_client_preserves_unknown_error_code():
4142

4243
assert exc_info.value.code == "PROVIDER_SPECIFIC"
4344
assert exc_info.value.details == {"x": 1}
45+
46+
47+
def test_client_preserves_unavailable_service_and_reason():
48+
client = AsyncHTTPClient(url="http://127.0.0.1:1933")
49+
50+
with pytest.raises(UnavailableError) as exc_info:
51+
client._raise_exception(
52+
{
53+
"code": "UNAVAILABLE",
54+
"message": "Storage backend unavailable: lock contention",
55+
"details": {
56+
"service": "storage backend",
57+
"reason": "failed to read lock token (os error 33)",
58+
},
59+
}
60+
)
61+
62+
assert str(exc_info.value) == (
63+
"Storage backend unavailable: failed to read lock token (os error 33)"
64+
)
65+
assert exc_info.value.details == {
66+
"service": "storage backend",
67+
"reason": "failed to read lock token (os error 33)",
68+
}

0 commit comments

Comments
 (0)