Skip to content

Commit 7ad398f

Browse files
authored
Merge pull request #1687 from weaviate/exception_orig_error
Add original error to exception
2 parents 1edf12e + 9d83bb5 commit 7ad398f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

weaviate/exceptions.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Weaviate Exceptions."""
22

33
from json.decoder import JSONDecodeError
4-
from typing import Tuple, Union, cast
4+
from typing import Optional, Tuple, Union, cast
55

66
import httpx
77
from grpc import Call, StatusCode # type: ignore
@@ -56,25 +56,34 @@ def __init__(self, message: str, response: Union[httpx.Response, AioRpcError, Ca
5656
)
5757
if response.status_code in ERROR_CODE_EXPLANATION:
5858
msg += " " + ERROR_CODE_EXPLANATION[response.status_code]
59+
60+
self.__error = body
5961
elif isinstance(response, AioRpcError):
6062
self._status_code = int(response.code().value[0])
6163
msg = (
6264
message
6365
+ f"! Unexpected status code: {response.code().value[1]}, with response body: {response.details()}."
6466
)
67+
self.__error: str | None = response.details()
6568
elif isinstance(response, Call):
6669
code = cast(StatusCode, response.code())
6770
self._status_code = int(code.value[0])
6871
msg = (
6972
message
7073
+ f"! Unexpected status code: {code.value[1]}, with response body: {response.details()}."
7174
)
75+
self.__error: str | None = response.details()
76+
7277
super().__init__(msg)
7378

7479
@property
7580
def status_code(self) -> int:
7681
return self._status_code
7782

83+
@property
84+
def error(self) -> Optional[str]:
85+
return self.__error
86+
7887

7988
UnexpectedStatusCodeException = UnexpectedStatusCodeError
8089

@@ -213,6 +222,11 @@ def __init__(self, message: str, protocol_type: str):
213222
msg = f"""Query call with protocol {protocol_type} failed with message {message}."""
214223
super().__init__(msg)
215224
self.message = message
225+
self.__error = message
226+
227+
@property
228+
def error(self) -> str:
229+
return self.__error
216230

217231

218232
WeaviateQueryException = WeaviateQueryError

0 commit comments

Comments
 (0)