Send localization info on websocket_api script errors (#104638)

* Send localization info on script errors

* Use connection exception hander

* Keep HomeAssistantError is unknown_error

* Move specific exception handling
This commit is contained in:
Jan Bouwhuis 2023-11-29 10:47:23 +01:00 committed by GitHub
parent 7dbaf40f48
commit efd330f182
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 3 deletions

View file

@ -778,7 +778,25 @@ async def handle_execute_script(
context = connection.context(msg)
script_obj = Script(hass, script_config, f"{const.DOMAIN} script", const.DOMAIN)
script_result = await script_obj.async_run(msg.get("variables"), context=context)
try:
script_result = await script_obj.async_run(
msg.get("variables"), context=context
)
except ServiceValidationError as err:
connection.logger.error(err)
connection.logger.debug("", exc_info=err)
connection.send_error(
msg["id"],
const.ERR_SERVICE_VALIDATION_ERROR,
str(err),
translation_domain=err.translation_domain,
translation_key=err.translation_key,
translation_placeholders=err.translation_placeholders,
)
return
except Exception as exc: # pylint: disable=broad-except
connection.async_handle_exception(msg, exc)
return
connection.send_result(
msg["id"],
{