Skip to content

Commit

Permalink
Add key checks to error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lawtancool committed Nov 25, 2023
1 parent 8f96a17 commit 6efb51c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyControl4/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ async def checkResponseForError(response_text: str):
elif await __checkResponseFormat(response_text) == "XML":
dictionary = xmltodict.parse(response_text)
if "C4ErrorResponse" in dictionary:
if dictionary["C4ErrorResponse"]["details"] in ERROR_DETAILS:
if (
"details" in dictionary["C4ErrorResponse"]
and dictionary["C4ErrorResponse"]["details"] in ERROR_DETAILS

Check warning on line 98 in pyControl4/error_handling.py

View workflow job for this annotation

GitHub Actions / Lint code with flake8

W503 line break before binary operator
):
exception = ERROR_DETAILS.get(dictionary["C4ErrorResponse"]["details"])
raise exception(response_text)
else:
Expand All @@ -102,14 +105,14 @@ async def checkResponseForError(response_text: str):
)
raise exception(response_text)
elif "code" in dictionary:
if dictionary["details"] in ERROR_DETAILS:
if "details" in dictionary and dictionary["details"] in ERROR_DETAILS:
exception = ERROR_DETAILS.get(dictionary["details"])
raise exception(response_text)
else:
exception = ERROR_CODES.get(str(dictionary["code"]), C4Exception)
raise exception(response_text)
elif "error" in dictionary:
if dictionary["details"] in DIRECTOR_ERROR_DETAILS:
if "details" in dictionary and dictionary["details"] in DIRECTOR_ERROR_DETAILS:
exception = DIRECTOR_ERROR_DETAILS.get(dictionary["details"])
raise exception(response_text)
else:
Expand Down

0 comments on commit 6efb51c

Please sign in to comment.