Fix KeyError when Twitter app permission is set to Read (#60018)

This commit is contained in:
Cliffano Subagio
2021-11-23 00:38:36 +11:00
committed by GitHub
parent 3b5a7d001f
commit a7382c8092

View File

@@ -243,7 +243,12 @@ class TwitterNotificationService(BaseNotificationService):
def log_error_resp(resp):
"""Log error response."""
obj = json.loads(resp.text)
error_message = obj["errors"]
if "errors" in obj:
error_message = obj["errors"]
elif "error" in obj:
error_message = obj["error"]
else:
error_message = resp.text
_LOGGER.error("Error %s: %s", resp.status_code, error_message)
@staticmethod