Skip to content

Commit

Permalink
Update rest.py (#22077)
Browse files Browse the repository at this point in the history
Added specific error logs for 5xx and 4xx responses, debug log for 2xx and other statuses.
  • Loading branch information
isabellaalstrom authored and balloob committed Mar 15, 2019
1 parent cf69f25 commit 9520d38
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions homeassistant/components/notify/rest.py
Expand Up @@ -139,8 +139,19 @@ def _data_template_creator(value):
params=data, timeout=10, auth=self._auth,
verify=self._verify_ssl)

success_codes = (200, 201, 202, 203, 204, 205, 206, 207, 208, 226)
if response.status_code not in success_codes:
if response.status_code >= 500 and response.status_code < 600:
_LOGGER.exception(
"Error sending message. Response %d: %s:",
"Server error. Response %d: %s:",
response.status_code, response.reason)
elif response.status_code >= 400 and response.status_code < 500:
_LOGGER.exception(
"Client error. Response %d: %s:",
response.status_code, response.reason)
elif response.status_code >= 200 and response.status_code < 300:
_LOGGER.debug(
"Success. Response %d: %s:",
response.status_code, response.reason)
else:
_LOGGER.debug(
"Response %d: %s:",
response.status_code, response.reason)

0 comments on commit 9520d38

Please sign in to comment.