Skip to content

Commit

Permalink
Merge pull request #229 from austinmroczek/fix-228
Browse files Browse the repository at this point in the history
Handle ResponseCode is None
  • Loading branch information
austinmroczek authored Dec 4, 2024
2 parents d228e05 + 8c4c242 commit f2e5d98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,10 @@ def tests_request_unknown_result_code(self):
with pytest.raises(BadResultCodeError):
TotalConnectClient("username", "password", usercodes=None)
assert mock_request.call_count == 1

def tests_empty_response_code(self):
"""Test an empty response code."""
# see issue #228
from total_connect_client.const import _ResultCode
with pytest.raises(ServiceUnavailable):
_ResultCode.from_response(None)
7 changes: 6 additions & 1 deletion total_connect_client/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum

from .exceptions import BadResultCodeError
from .exceptions import BadResultCodeError, ServiceUnavailable


class ArmType(Enum):
Expand Down Expand Up @@ -149,6 +149,9 @@ class _ResultCode(Enum):
def from_response(response_dict):
try:
return _ResultCode(response_dict["ResultCode"])
except TypeError:
# sometimes when there are server issues, it returns empty responses - see issue #228
raise ServiceUnavailable(f"Server returned empty response, check server status at {STATUS_URL}") from None
except ValueError:
raise BadResultCodeError(
f"unknown result code {response_dict['ResultCode']}", response_dict
Expand Down Expand Up @@ -178,3 +181,5 @@ def from_response(response_dict):


PROJECT_URL = "https://github.com/craigjmidwinter/total-connect-client"

STATUS_URL = "https://status.resideo.com/"

0 comments on commit f2e5d98

Please sign in to comment.