|
1 | 1 | """Weaviate Exceptions.""" |
2 | 2 |
|
3 | 3 | from json.decoder import JSONDecodeError |
4 | | -from typing import Tuple, Union, cast |
| 4 | +from typing import Optional, Tuple, Union, cast |
5 | 5 |
|
6 | 6 | import httpx |
7 | 7 | from grpc import Call, StatusCode # type: ignore |
@@ -56,25 +56,34 @@ def __init__(self, message: str, response: Union[httpx.Response, AioRpcError, Ca |
56 | 56 | ) |
57 | 57 | if response.status_code in ERROR_CODE_EXPLANATION: |
58 | 58 | msg += " " + ERROR_CODE_EXPLANATION[response.status_code] |
| 59 | + |
| 60 | + self.__error = body |
59 | 61 | elif isinstance(response, AioRpcError): |
60 | 62 | self._status_code = int(response.code().value[0]) |
61 | 63 | msg = ( |
62 | 64 | message |
63 | 65 | + f"! Unexpected status code: {response.code().value[1]}, with response body: {response.details()}." |
64 | 66 | ) |
| 67 | + self.__error: str | None = response.details() |
65 | 68 | elif isinstance(response, Call): |
66 | 69 | code = cast(StatusCode, response.code()) |
67 | 70 | self._status_code = int(code.value[0]) |
68 | 71 | msg = ( |
69 | 72 | message |
70 | 73 | + f"! Unexpected status code: {code.value[1]}, with response body: {response.details()}." |
71 | 74 | ) |
| 75 | + self.__error: str | None = response.details() |
| 76 | + |
72 | 77 | super().__init__(msg) |
73 | 78 |
|
74 | 79 | @property |
75 | 80 | def status_code(self) -> int: |
76 | 81 | return self._status_code |
77 | 82 |
|
| 83 | + @property |
| 84 | + def error(self) -> Optional[str]: |
| 85 | + return self.__error |
| 86 | + |
78 | 87 |
|
79 | 88 | UnexpectedStatusCodeException = UnexpectedStatusCodeError |
80 | 89 |
|
@@ -213,6 +222,11 @@ def __init__(self, message: str, protocol_type: str): |
213 | 222 | msg = f"""Query call with protocol {protocol_type} failed with message {message}.""" |
214 | 223 | super().__init__(msg) |
215 | 224 | self.message = message |
| 225 | + self.__error = message |
| 226 | + |
| 227 | + @property |
| 228 | + def error(self) -> str: |
| 229 | + return self.__error |
216 | 230 |
|
217 | 231 |
|
218 | 232 | WeaviateQueryException = WeaviateQueryError |
|
0 commit comments