diff --git a/homeassistant/components/application_credentials/__init__.py b/homeassistant/components/application_credentials/__init__.py index 0dda775774f..9117a91c33d 100644 --- a/homeassistant/components/application_credentials/__init__.py +++ b/homeassistant/components/application_credentials/__init__.py @@ -17,6 +17,7 @@ from homeassistant.components import websocket_api from homeassistant.components.websocket_api.connection import ActiveConnection from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_DOMAIN, CONF_ID from homeassistant.core import HomeAssistant, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import collection, config_entry_oauth2_flow import homeassistant.helpers.config_validation as cv from homeassistant.helpers.storage import Store @@ -98,7 +99,9 @@ class ApplicationCredentialsStorageCollection(collection.StorageCollection): entries = self.hass.config_entries.async_entries(current[CONF_DOMAIN]) for entry in entries: if entry.data.get("auth_implementation") == item_id: - raise ValueError("Cannot delete credential in use by an integration") + raise HomeAssistantError( + f"Cannot delete credential in use by integration {entry.domain}" + ) await super().async_delete_item(item_id) diff --git a/tests/components/application_credentials/test_init.py b/tests/components/application_credentials/test_init.py index b5f51a9b837..b62f8a0139c 100644 --- a/tests/components/application_credentials/test_init.py +++ b/tests/components/application_credentials/test_init.py @@ -445,6 +445,10 @@ async def test_config_flow( assert not resp.get("success") assert "error" in resp assert resp["error"].get("code") == "unknown_error" + assert ( + resp["error"].get("message") + == "Cannot delete credential in use by integration fake_integration" + ) async def test_config_flow_multiple_entries(