Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DVX-531: Make AtlanError message more descriptive #353

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyatlan/client/atlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _call_api_internal(
SimpleNamespace(
http_error_code=response.status_code,
error_id=f"ATLAN-PYTHON-{response.status_code}-000",
error_message="",
error_message=response.text,
user_action=ErrorCode.ERROR_PASSTHROUGH.user_action,
)
)
Expand Down
5 changes: 4 additions & 1 deletion pyatlan/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class ErrorInfo(Protocol):

class AtlanError(Exception):
def __init__(self, error_code: ErrorInfo, *args):
message = error_code.error_message.format(*args)
try:
message = error_code.error_message.format(*args)
except KeyError:
message = error_code.error_message
super().__init__(message)
self.error_code = error_code

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,38 @@ def test_user_client_methods_validation_error(client, method, params):
assert error_msg in str(err.value)


@pytest.mark.parametrize(
"test_error_msg",
[
"{'error': 123}",
"{'error': 123, 'code': 465}",
"{'error': 123} with text",
"Some error message...",
],
)
@patch.object(AtlanClient, "_session")
def test_atlan_call_api_server_error_messages(
mock_session,
client: AtlanClient,
test_error_msg,
):
mock_response = Mock()
mock_response.status_code = 500
mock_response.text = test_error_msg
mock_session.request.return_value = mock_response
glossary = AtlasGlossary.creator(name="test-glossary")

with pytest.raises(
AtlanError,
match=(
f"ATLAN-PYTHON-500-000 {test_error_msg} "
"Suggestion: Check the details of the "
"server's message to correct your request."
),
):
client.asset.save(glossary)


class TestBatch:
def test_init(self, mock_asset_client):
sut = Batch(client=mock_asset_client, max_size=10)
Expand Down
Loading