From fe689897191f8541468a74a0ad8668f805f6916f Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sat, 14 May 2022 13:51:02 -0700 Subject: [PATCH] Add error handling for application credentials removal --- .../ha-config-application-credentials.ts | 28 +++++++++++++++---- src/translations/en.json | 3 +- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/panels/config/application_credentials/ha-config-application-credentials.ts b/src/panels/config/application_credentials/ha-config-application-credentials.ts index fa55f076811d..3e8e2f036d1f 100644 --- a/src/panels/config/application_credentials/ha-config-application-credentials.ts +++ b/src/panels/config/application_credentials/ha-config-application-credentials.ts @@ -19,7 +19,10 @@ import { fetchApplicationCredentials, } from "../../../data/application_credential"; import { domainToName } from "../../../data/integration"; -import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; +import { + showAlertDialog, + showConfirmationDialog, +} from "../../../dialogs/generic/show-dialog-box"; import "../../../layouts/hass-tabs-subpage-data-table"; import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-data-table"; import { HomeAssistant, Route } from "../../../types"; @@ -171,11 +174,24 @@ export class HaConfigApplicationCredentials extends LitElement { confirmText: this.hass.localize("ui.common.remove"), dismissText: this.hass.localize("ui.common.cancel"), confirm: async () => { - await Promise.all( - this._selected.map(async (applicationCredential) => { - await deleteApplicationCredential(this.hass, applicationCredential); - }) - ); + try { + await Promise.all( + this._selected.map(async (applicationCredential) => { + await deleteApplicationCredential( + this.hass, + applicationCredential + ); + }) + ); + } catch (err: any) { + showAlertDialog(this, { + title: this.hass.localize( + "ui.panel.config.application_credentials.picker.remove_selected.error_title" + ), + text: err.message, + }); + return; + } this._dataTable.clearSelection(); this._fetchApplicationCredentials(); }, diff --git a/src/translations/en.json b/src/translations/en.json index 550d03c62723..bc1ec4d044d9 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2877,7 +2877,8 @@ "remove_selected": { "button": "Remove selected", "confirm_title": "Do you want to remove {number} {number, plural,\n one {credential}\n other {credentialss}\n}?", - "confirm_text": "Application Credentials in use by an integration may not be removed." + "confirm_text": "Application Credentials in use by an integration may not be removed.", + "error_title": "Removing Application Credential failed" }, "selected": "{number} selected" }