Skip to content

Commit

Permalink
[Tables] Raise an error while failed to decode response (#24788)
Browse files Browse the repository at this point in the history
  • Loading branch information
YalinLi0312 authored Jul 9, 2022
1 parent bd68763 commit c004d5c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
* Fix handling of client-side exceptions that get raised during service requests (such as [#21416](https://github.com/Azure/azure-sdk-for-python/issues/21416)) ([#24788](https://github.com/Azure/azure-sdk-for-python/pull/24788))

### Other Changes

Expand Down
5 changes: 4 additions & 1 deletion sdk/tables/azure-data-tables/azure/data/tables/_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ def _reraise_error(decoded_error):


def _process_table_error(storage_error, table_name=None):
decoded_error = _decode_error(storage_error.response, storage_error.message)
try:
decoded_error = _decode_error(storage_error.response, storage_error.message)
except AttributeError:
raise storage_error
if table_name:
_validate_tablename_error(decoded_error, table_name)
_reraise_error(decoded_error)
Expand Down
19 changes: 19 additions & 0 deletions sdk/tables/azure-data-tables/tests/test_table_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
UpdateMode
)
from azure.data.tables._common_conversion import TZ_UTC
from azure.identity import DefaultAzureCredential

from azure.core import MatchConditions
from azure.core.credentials import AzureSasCredential
from azure.core.exceptions import (
ClientAuthenticationError,
HttpResponseError,
ResourceNotFoundError,
ResourceExistsError,
Expand Down Expand Up @@ -2236,3 +2238,20 @@ def test_upsert_entity_with_invalid_key_type(self, tables_storage_account_name,
self.table.upsert_entity(entity2)
finally:
self._tear_down()

@tables_decorator
def test_list_tables_with_invalid_credential(self, tables_storage_account_name, tables_primary_storage_account_key):
account_url = self.account_url(tables_storage_account_name, "table")
credential = DefaultAzureCredential(
exclude_environment_credential=True,
exclude_managed_identity_credential=False,
exclude_shared_token_cache_credential=True,
exclude_visual_studio_code_credential=True,
exclude_cli_credential=True,
exclude_interactive_browser_credential=True,
exclude_powershell_credential=True,
)
client = TableServiceClient(credential=credential, endpoint=account_url, api_version="2020-12-06")
with pytest.raises(ClientAuthenticationError):
for _ in client.list_tables():
pass
19 changes: 19 additions & 0 deletions sdk/tables/azure-data-tables/tests/test_table_entity_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from azure.core import MatchConditions
from azure.core.credentials import AzureSasCredential
from azure.core.exceptions import (
ClientAuthenticationError,
HttpResponseError,
ResourceNotFoundError,
ResourceExistsError,
Expand All @@ -35,6 +36,7 @@
)
from azure.data.tables.aio import TableServiceClient
from azure.data.tables._common_conversion import TZ_UTC
from azure.identity import DefaultAzureCredential

from _shared.asynctestcase import AsyncTableTestCase
from async_preparers import tables_decorator_async
Expand Down Expand Up @@ -2230,3 +2232,20 @@ async def test_upsert_entity_with_invalid_key_type(self, tables_storage_account_
await self.table.upsert_entity(entity2)
finally:
await self._tear_down()

@tables_decorator_async
async def test_list_tables_with_invalid_credential(self, tables_storage_account_name, tables_primary_storage_account_key):
account_url = self.account_url(tables_storage_account_name, "table")
credential = DefaultAzureCredential(
exclude_environment_credential=True,
exclude_managed_identity_credential=False,
exclude_shared_token_cache_credential=True,
exclude_visual_studio_code_credential=True,
exclude_cli_credential=True,
exclude_interactive_browser_credential=True,
exclude_powershell_credential=True,
)
client = TableServiceClient(credential=credential, endpoint=account_url, api_version="2020-12-06")
with pytest.raises(ClientAuthenticationError):
async for _ in client.list_tables():
pass

0 comments on commit c004d5c

Please sign in to comment.