Skip to content

Commit

Permalink
bugfix: fix error message printing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Baldy committed Apr 4, 2024
1 parent 118ef8d commit 368b229
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pylxd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def __init__(self, response):
def __str__(self):
if self.response.status_code == 200: # Operation failure
try:
return self.response.json()["metadata"]["err"]
json_response = self.response.json()
if "error" in json_response:
return json_response["error"]
metadata = json_response.get("metadata")
if metadata and isinstance(metadata, dict) and "err" in metadata:
return json_response["metadata"]["err"]
return json_response

Check warning on line 26 in pylxd/exceptions.py

View check run for this annotation

Codecov / codecov/patch

pylxd/exceptions.py#L20-L26

Added lines #L20 - L26 were not covered by tests
except (ValueError, KeyError):
pass

Expand Down

0 comments on commit 368b229

Please sign in to comment.