diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index 15aa9e82f61b80..471bbc4745aa72 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -270,7 +270,7 @@ async def handle_call_service( connection.logger.debug("", exc_info=err) connection.send_error( msg["id"], - const.ERR_HOME_ASSISTANT_ERROR, + const.ERR_SERVICE_VALIDATION_ERROR, f"Validation error: {err}", translation_domain=err.translation_domain, translation_key=err.translation_key, diff --git a/homeassistant/components/websocket_api/const.py b/homeassistant/components/websocket_api/const.py index 4b9a0943d9a294..9a44f80a5c8b77 100644 --- a/homeassistant/components/websocket_api/const.py +++ b/homeassistant/components/websocket_api/const.py @@ -32,6 +32,7 @@ ERR_NOT_FOUND: Final = "not_found" ERR_NOT_SUPPORTED: Final = "not_supported" ERR_HOME_ASSISTANT_ERROR: Final = "home_assistant_error" +ERR_SERVICE_VALIDATION_ERROR: Final = "service_validation_error" ERR_UNKNOWN_COMMAND: Final = "unknown_command" ERR_UNKNOWN_ERROR: Final = "unknown_error" ERR_UNAUTHORIZED: Final = "unauthorized" diff --git a/homeassistant/components/websocket_api/messages.py b/homeassistant/components/websocket_api/messages.py index fae310f9f80027..34ca6886b5eddc 100644 --- a/homeassistant/components/websocket_api/messages.py +++ b/homeassistant/components/websocket_api/messages.py @@ -78,8 +78,6 @@ def error_message( "code": code, "message": message, } - # In case a ServiceNotFound error is raised - # we use 'websocket_api' as default translation_domain. # In case `translation_key` is `None` we do not set it, nor the # `translation`_placeholders` and `translation_domain`. if translation_key is not None: diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 1784b7ef45208a..34424545666028 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -526,7 +526,7 @@ async def unknown_error_call(_): assert msg["id"] == 6 assert msg["type"] == const.TYPE_RESULT assert msg["success"] is False - assert msg["error"]["code"] == "home_assistant_error" + assert msg["error"]["code"] == "service_validation_error" assert msg["error"]["message"] == "Validation error: error_message" assert msg["error"]["translation_placeholders"] == {"option": "bla"} assert msg["error"]["translation_key"] == "custom_error"