Skip to content

Commit

Permalink
Merge pull request #344 from atlanhq/DVX-500
Browse files Browse the repository at this point in the history
DVX-500 Update  to include user action when throwing an exception
  • Loading branch information
ErnestoLoma committed Jun 3, 2024
2 parents 4ae671e + 617304b commit afd13bb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
50 changes: 26 additions & 24 deletions pyatlan/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class AtlanError(Exception):
def __init__(self, error_code: ErrorInfo, *args):
message = error_code.error_message.format(*args)
super().__init__(message)
self.code = error_code.error_id
self.status_code = error_code.http_error_code
self.error_code = error_code

def __str__(self):
return f"{self.code or ''} {super().__str__()}"
return (
f"{self.error_code.error_id or ''} "
f"{super().__str__()} Suggestion: {self.error_code.user_action}"
)


class ApiConnectionError(AtlanError):
Expand Down Expand Up @@ -90,7 +92,7 @@ class ErrorCode(Enum):
INVALID_REQUEST_PASSTHROUGH = (
400,
"ATLAN-PYTHON-400-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
InvalidRequestError,
)
Expand Down Expand Up @@ -431,43 +433,43 @@ class ErrorCode(Enum):
INVALID_PARAMETER_TYPE = (
400,
"ATLAN-PYTHON-400-048",
"Invalid parameter type for {0} should be {1}",
"Invalid parameter type for {0} should be {1}.",
"Check that you have used the correct type of parameter.",
InvalidRequestError,
)
GLOSSARY_MISSING_QUALIFIED_NAME = (
400,
"ATLAN-PYTHON-400-049",
"The qualified_name is not present in the Glossary",
"Check that the qualified_name is available from the Glossary",
"The qualified_name is not present in the Glossary.",
"Check that the qualified_name is available from the Glossary.",
InvalidRequestError,
)
MISSING_OPTIONS = (
400,
"ATLAN-PYTHON-400-050",
"Options is not present in the AttributeDef",
"Please use the AttributeDef.create function to create the Options",
"Options is not present in the AttributeDef.",
"Please use the AttributeDef.create function to create the Options.",
InvalidRequestError,
)
INVALID_PARAMETER_VALUE = (
400,
"ATLAN-PYTHON-400-051",
"{0} is an invalid value for {1} should be in {2}",
"Check that value you are using is valid",
"{0} is an invalid value for {1} should be in {2}.",
"Check that value you are using is valid.",
InvalidRequestError,
)
ASSET_CAN_NOT_BE_ARCHIVED = (
400,
"ATLAN-PYTHON-400-052",
"Asset with guid: {0} is an asset of type {1} which does not support archiving",
"Please use purge if you wish to remove assets of this type",
"Asset with guid: {0} is an asset of type {1} which does not support archiving.",
"Please use purge if you wish to remove assets of this type.",
InvalidRequestError,
)
METHOD_CAN_NOT_BE_INVOKED_ON_ASSET = (
400,
"ATLAN-PYTHON-400-053",
"This method cannot be invoked on the Asset class. Please invoke on a specific asset type",
"Please invoke this method on a sub-class of Asset",
"This method cannot be invoked on the Asset class. Please invoke on a specific asset type.",
"Please invoke this method on a sub-class of Asset.",
InvalidRequestError,
)
INVALID_CREDENTIALS = (
Expand Down Expand Up @@ -510,14 +512,14 @@ class ErrorCode(Enum):
INVALID_UPLOAD_FILE_PATH = (
400,
"ATLAN-PYTHON-400-059",
"Unable to upload file, Error: {0}, Path: {1}",
"Unable to upload file, Error: {0}, Path: {1}.",
"Please check the provided file path for upload.",
InvalidRequestError,
)
UNABLE_TO_DOWNLOAD_FILE = (
400,
"ATLAN-PYTHON-400-060",
"Unable to download file, Error: {0}, Path: {1}",
"Unable to download file, Error: {0}, Path: {1}.",
"Please check the provided download file type and path.",
InvalidRequestError,
)
Expand All @@ -531,7 +533,7 @@ class ErrorCode(Enum):
AUTHENTICATION_PASSTHROUGH = (
401,
"ATLAN-PYTHON-401-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
AuthenticationError,
)
Expand Down Expand Up @@ -575,7 +577,7 @@ class ErrorCode(Enum):
PERMISSION_PASSTHROUGH = (
403,
"ATLAN-PYTHON-403-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
PermissionError,
)
Expand All @@ -596,7 +598,7 @@ class ErrorCode(Enum):
NOT_FOUND_PASSTHROUGH = (
404,
"ATLAN-PYTHON-404-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
NotFoundError,
)
Expand Down Expand Up @@ -807,7 +809,7 @@ class ErrorCode(Enum):
CONFLICT_PASSTHROUGH = (
409,
"ATLAN-PYTHON-409-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
ConflictError,
)
Expand All @@ -823,14 +825,14 @@ class ErrorCode(Enum):
RATE_LIMIT_PASSTHROUGH = (
429,
"ATLAN-PYTHON-429-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
RateLimitError,
)
ERROR_PASSTHROUGH = (
500,
"ATLAN-PYTHON-500-000",
"Server responded with {0}: {1}",
"Server responded with {0}: {1}.",
"Check the details of the server's message to correct your request.",
ApiError,
)
Expand All @@ -844,7 +846,7 @@ class ErrorCode(Enum):
UNABLE_TO_DESERIALIZE = (
500,
"ATLAN-PYTHON-500-002",
"Unable to deserialize value: {0}",
"Unable to deserialize value: {0}.",
RAISE_GITHUB_ISSUE,
LogicError,
)
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/glossary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ def test_category_delete_by_guid_raises_error_invalid_request_error(
with pytest.raises(
InvalidRequestError,
match=f"ATLAN-PYTHON-400-052 Asset with guid: {category.guid} is an asset "
f"of type AtlasGlossaryCategory which does not support archiving",
"of type AtlasGlossaryCategory which does not support archiving. "
"Suggestion: Please use purge if you wish to remove assets of this type.",
):
client.asset.delete_by_guid(guid=category.guid)

Expand Down Expand Up @@ -944,7 +945,8 @@ def test_remove_unrelated_relationship(
EXPECTED_ERR = (
"ATLAN-PYTHON-404-000 Server responded with ATLAS-409-00-0021: "
"relationship AtlasGlossaryRelatedTerm does "
f"not exist between entities {term2.guid} and {term1.guid}"
f"not exist between entities {term2.guid} and {term1.guid}. "
"Suggestion: Check the details of the server's message to correct your request."
)
assert EXPECTED_ERR == str(err.value)

Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,17 +961,20 @@ def validate_filter(filter_, filter_condition, results):
(
"include_in_results",
1,
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter",
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter. "
r"Suggestion: Check that you have used the correct type of parameter.",
),
(
"where_assets",
1,
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter",
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter. "
r"Suggestion: Check that you have used the correct type of parameter.",
),
(
"where_relationships",
1,
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter",
r"ATLAN-PYTHON-400-048 Invalid parameter type for lineage_filter should be LineageFilter. "
r"Suggestion: Check that you have used the correct type of parameter.",
),
],
)
Expand Down

0 comments on commit afd13bb

Please sign in to comment.