diff --git a/azure-kusto-data/azure/kusto/data/exceptions.py b/azure-kusto-data/azure/kusto/data/exceptions.py index 5abcbd68..3da752fe 100644 --- a/azure-kusto-data/azure/kusto/data/exceptions.py +++ b/azure-kusto-data/azure/kusto/data/exceptions.py @@ -120,9 +120,12 @@ class KustoApiError(KustoServiceError): Represents a standard API error from kusto. Use `get_api_error()` to retrieve more details. """ - def __init__(self, error_dict: dict, message: str = None, http_response: "Union[requests.Response, ClientResponse, None]" = None, kusto_response=None): + def __init__( + self, error_dict: dict, message: Optional[str] = None, http_response: "Union[requests.Response, ClientResponse, None]" = None, kusto_response=None + ): self.error = OneApiError.from_dict(error_dict["error"]) - super().__init__(message or self.error.description, http_response, kusto_response) + service_error_message = message or self.error.description or "Unknown Kusto service error" + super().__init__(service_error_message, http_response, kusto_response) def get_api_error(self) -> OneApiError: return self.error diff --git a/azure-kusto-data/tests/test_exceptions.py b/azure-kusto-data/tests/test_exceptions.py index 9840d9b7..1e9cd1b3 100644 --- a/azure-kusto-data/tests/test_exceptions.py +++ b/azure-kusto-data/tests/test_exceptions.py @@ -1,4 +1,4 @@ -from azure.kusto.data.exceptions import OneApiError +from azure.kusto.data.exceptions import KustoApiError, OneApiError def test_parse_one_api_error(): @@ -101,3 +101,12 @@ def test_one_api_error_no_code_fail(): assert result.code == "FailedToParse" assert result.type == "FailedToParseOneApiError" assert not result.permanent + + +def test_kusto_api_error_without_message_no_exception_raised(): + error_dict = {"error": {"code": "400", "message": "This is a sample error message."}} + + try: + KustoApiError(error_dict, http_response=None) + except Exception: + assert False, "Exception was raised"