Assign specific error code for HomeAssistantError on websocket_api connection exceptions (#104700)
Assign specific error code for HomeAssistantErrorpull/104711/head
parent
9741380cc0
commit
861bb48ab6
|
@ -271,7 +271,7 @@ class ActiveConnection:
|
|||
err_message = "Timeout"
|
||||
elif isinstance(err, HomeAssistantError):
|
||||
err_message = str(err)
|
||||
code = const.ERR_UNKNOWN_ERROR
|
||||
code = const.ERR_HOME_ASSISTANT_ERROR
|
||||
translation_domain = err.translation_domain
|
||||
translation_key = err.translation_key
|
||||
translation_placeholders = err.translation_placeholders
|
||||
|
|
|
@ -479,7 +479,7 @@ async def test_config_flow(
|
|||
resp = await client.cmd("delete", {"application_credentials_id": ID})
|
||||
assert not resp.get("success")
|
||||
assert "error" in resp
|
||||
assert resp["error"].get("code") == "unknown_error"
|
||||
assert resp["error"].get("code") == "home_assistant_error"
|
||||
assert (
|
||||
resp["error"].get("message")
|
||||
== "Cannot delete credential in use by integration fake_integration"
|
||||
|
|
|
@ -438,7 +438,7 @@ async def test_delete_blueprint_in_use_by_automation(
|
|||
assert msg["id"] == 9
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {
|
||||
"code": "unknown_error",
|
||||
"code": "home_assistant_error",
|
||||
"message": "Blueprint in use",
|
||||
}
|
||||
|
||||
|
@ -484,6 +484,6 @@ async def test_delete_blueprint_in_use_by_script(
|
|||
assert msg["id"] == 9
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {
|
||||
"code": "unknown_error",
|
||||
"code": "home_assistant_error",
|
||||
"message": "Blueprint in use",
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ async def test_remove_config_entry_from_device(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
|
||||
# Make async_remove_config_entry_device return True
|
||||
can_remove = True
|
||||
|
@ -365,7 +365,7 @@ async def test_remove_config_entry_from_device_fails(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert response["error"]["message"] == "Unknown config entry"
|
||||
|
||||
# Try removing a config entry which does not support removal from the device
|
||||
|
@ -380,7 +380,7 @@ async def test_remove_config_entry_from_device_fails(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert (
|
||||
response["error"]["message"] == "Config entry does not support device removal"
|
||||
)
|
||||
|
@ -397,7 +397,7 @@ async def test_remove_config_entry_from_device_fails(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert response["error"]["message"] == "Unknown device"
|
||||
|
||||
# Try removing a config entry from a device which it's not connected to
|
||||
|
@ -428,7 +428,7 @@ async def test_remove_config_entry_from_device_fails(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert response["error"]["message"] == "Config entry not in device"
|
||||
|
||||
# Try removing a config entry which can't be loaded from a device - allowed
|
||||
|
@ -443,5 +443,5 @@ async def test_remove_config_entry_from_device_fails(
|
|||
response = await ws_client.receive_json()
|
||||
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert response["error"]["message"] == "Integration not found"
|
||||
|
|
|
@ -296,7 +296,7 @@ async def test_remove_device(
|
|||
)
|
||||
response = await ws_client.receive_json()
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# try to delete orphan_device
|
||||
|
|
|
@ -699,4 +699,4 @@ async def test_option_flow_sensor_preview_config_entry_removed(
|
|||
)
|
||||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {"code": "unknown_error", "message": "Unknown error"}
|
||||
assert msg["error"] == {"code": "home_assistant_error", "message": "Unknown error"}
|
||||
|
|
|
@ -740,7 +740,7 @@ async def test_update_duplicates(
|
|||
)
|
||||
resp = await client.receive_json()
|
||||
assert not resp["success"]
|
||||
assert resp["error"]["code"] == "unknown_error"
|
||||
assert resp["error"]["code"] == "home_assistant_error"
|
||||
assert resp["error"]["message"] == "Duplicate options are not allowed"
|
||||
|
||||
state = hass.states.get(input_entity_id)
|
||||
|
@ -812,7 +812,7 @@ async def test_ws_create_duplicates(
|
|||
)
|
||||
resp = await client.receive_json()
|
||||
assert not resp["success"]
|
||||
assert resp["error"]["code"] == "unknown_error"
|
||||
assert resp["error"]["code"] == "home_assistant_error"
|
||||
assert resp["error"]["message"] == "Duplicate options are not allowed"
|
||||
|
||||
assert not hass.states.get(input_entity_id)
|
||||
|
|
|
@ -131,5 +131,5 @@ async def test_tag_id_exists(
|
|||
await client.send_json({"id": 2, "type": f"{DOMAIN}/create", "tag_id": "test tag"})
|
||||
response = await client.receive_json()
|
||||
assert not response["success"]
|
||||
assert response["error"]["code"] == "unknown_error"
|
||||
assert response["error"]["code"] == "home_assistant_error"
|
||||
assert len(changes) == 0
|
||||
|
|
|
@ -845,4 +845,4 @@ async def test_option_flow_sensor_preview_config_entry_removed(
|
|||
)
|
||||
msg = await client.receive_json()
|
||||
assert not msg["success"]
|
||||
assert msg["error"] == {"code": "unknown_error", "message": "Unknown error"}
|
||||
assert msg["error"] == {"code": "home_assistant_error", "message": "Unknown error"}
|
||||
|
|
|
@ -2327,7 +2327,7 @@ async def test_execute_script(
|
|||
translation_key="test_error",
|
||||
translation_placeholders={"option": "bla"},
|
||||
),
|
||||
"unknown_error",
|
||||
"home_assistant_error",
|
||||
),
|
||||
(
|
||||
ServiceValidationError(
|
||||
|
|
|
@ -39,15 +39,15 @@ from tests.common import MockUser
|
|||
),
|
||||
(
|
||||
exceptions.HomeAssistantError("Failed to do X"),
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
websocket_api.ERR_HOME_ASSISTANT_ERROR,
|
||||
"Failed to do X",
|
||||
"Error handling message: Failed to do X (unknown_error) Mock User from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Failed to do X (home_assistant_error) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
exceptions.ServiceValidationError("Failed to do X"),
|
||||
websocket_api.ERR_UNKNOWN_ERROR,
|
||||
websocket_api.ERR_HOME_ASSISTANT_ERROR,
|
||||
"Failed to do X",
|
||||
"Error handling message: Failed to do X (unknown_error) Mock User from 127.0.0.42 (Browser)",
|
||||
"Error handling message: Failed to do X (home_assistant_error) Mock User from 127.0.0.42 (Browser)",
|
||||
),
|
||||
(
|
||||
ValueError("Really bad"),
|
||||
|
|
Loading…
Reference in New Issue