Fix exception handling in Microsoft TTS (#92556)

pycsspeechtts uses the requests library, but Microsoft TTS previously
caught HTTPException from the standard library. This is changed to
catch requests.HTTPError and return `(None, None)` consistent with
other TTS integrations. This will properly raise HomeAssistantError
for display in the frontend.

Follow up to PR #92215 which adds tests for Microsoft TTS.
This commit is contained in:
Dara Adib
2023-05-25 11:29:13 +02:00
committed by GitHub
parent 4ef315b32a
commit e2daffc117
2 changed files with 4 additions and 6 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
"""Support for the Microsoft Cognitive Services text-to-speech service."""
from http.client import HTTPException
import logging
from pycsspeechtts import pycsspeechtts
from requests.exceptions import HTTPError
import voluptuous as vol
from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
@@ -121,7 +121,7 @@ class MicrosoftProvider(Provider):
contour=self._contour,
text=message,
)
except HTTPException as ex:
except HTTPError as ex:
_LOGGER.error("Error occurred for Microsoft TTS: %s", ex)
return (None, None)
return ("mp3", data)