From 80cde44d805ea8497864548b2d8e1fd52b35bc73 Mon Sep 17 00:00:00 2001 From: jbouwh Date: Mon, 30 Oct 2023 15:49:08 +0000 Subject: [PATCH] Follow up comment --- homeassistant/components/websocket_api/commands.py | 2 +- homeassistant/components/websocket_api/const.py | 1 + homeassistant/components/websocket_api/messages.py | 2 -- tests/components/websocket_api/test_commands.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index a53a31a5ae10d7..d03b94726b525c 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -263,7 +263,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 fdedbb2fe38fcc..79733472c8a7d9 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"