From 54d6b5b6f32323649743c00b97ef8138f52d745a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 1 Feb 2022 11:22:14 +0100 Subject: [PATCH] Handle config flow errors better (#11499) * Handle config flow errors better * Use body for error message * Update dialog-data-entry-flow.ts --- .../config-flow/dialog-data-entry-flow.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dialogs/config-flow/dialog-data-entry-flow.ts b/src/dialogs/config-flow/dialog-data-entry-flow.ts index c8273d7825..29bea7491e 100644 --- a/src/dialogs/config-flow/dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/dialog-data-entry-flow.ts @@ -116,15 +116,14 @@ class DataEntryFlowDialog extends LitElement { params.continueFlowId ); } catch (err: any) { - this._step = undefined; - this._params = undefined; + this.closeDialog(); showAlertDialog(this, { title: this.hass.localize( "ui.panel.config.integrations.config_flow.error" ), - text: this.hass.localize( + text: `${this.hass.localize( "ui.panel.config.integrations.config_flow.could_not_load" - ), + )}: ${err.message || err.body}`, }); return; } @@ -177,6 +176,7 @@ class DataEntryFlowDialog extends LitElement { }); } + this._loading = undefined; this._step = undefined; this._params = undefined; this._devices = undefined; @@ -372,15 +372,14 @@ class DataEntryFlowDialog extends LitElement { try { step = await this._params!.flowConfig.createFlow(this.hass, handler); } catch (err: any) { - this._step = undefined; - this._params = undefined; + this.closeDialog(); showAlertDialog(this, { title: this.hass.localize( "ui.panel.config.integrations.config_flow.error" ), - text: this.hass.localize( + text: `${this.hass.localize( "ui.panel.config.integrations.config_flow.could_not_load" - ), + )}: ${err.message || err.body}`, }); return; } finally { @@ -405,6 +404,15 @@ class DataEntryFlowDialog extends LitElement { this._loading = "loading_step"; try { this._step = await step; + } catch (err: any) { + this.closeDialog(); + showAlertDialog(this, { + title: this.hass.localize( + "ui.panel.config.integrations.config_flow.error" + ), + text: err.message || err.body, + }); + return; } finally { this._loading = undefined; }