Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion weaviate/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Weaviate Exceptions."""

from json.decoder import JSONDecodeError
from typing import Tuple, Union, cast
from typing import Optional, Tuple, Union, cast

import httpx
from grpc import Call, StatusCode # type: ignore
Expand Down Expand Up @@ -56,25 +56,34 @@ def __init__(self, message: str, response: Union[httpx.Response, AioRpcError, Ca
)
if response.status_code in ERROR_CODE_EXPLANATION:
msg += " " + ERROR_CODE_EXPLANATION[response.status_code]

self.__error = body
elif isinstance(response, AioRpcError):
self._status_code = int(response.code().value[0])
msg = (
message
+ f"! Unexpected status code: {response.code().value[1]}, with response body: {response.details()}."
)
self.__error: str | None = response.details()
elif isinstance(response, Call):
code = cast(StatusCode, response.code())
self._status_code = int(code.value[0])
msg = (
message
+ f"! Unexpected status code: {code.value[1]}, with response body: {response.details()}."
)
self.__error: str | None = response.details()

super().__init__(msg)

@property
def status_code(self) -> int:
return self._status_code

@property
def error(self) -> Optional[str]:
return self.__error


UnexpectedStatusCodeException = UnexpectedStatusCodeError

Expand Down Expand Up @@ -213,6 +222,11 @@ def __init__(self, message: str, protocol_type: str):
msg = f"""Query call with protocol {protocol_type} failed with message {message}."""
super().__init__(msg)
self.message = message
self.__error = message

@property
def error(self) -> str:
return self.__error


WeaviateQueryException = WeaviateQueryError
Expand Down
Loading