Handle config flow errors better (#11499)

* Handle config flow errors better

* Use body for error message

* Update dialog-data-entry-flow.ts
This commit is contained in:
Bram Kragten 2022-02-01 11:22:14 +01:00 committed by GitHub
parent fb55ab197f
commit 54d6b5b6f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,15 +116,14 @@ class DataEntryFlowDialog extends LitElement {
params.continueFlowId params.continueFlowId
); );
} catch (err: any) { } catch (err: any) {
this._step = undefined; this.closeDialog();
this._params = undefined;
showAlertDialog(this, { showAlertDialog(this, {
title: this.hass.localize( title: this.hass.localize(
"ui.panel.config.integrations.config_flow.error" "ui.panel.config.integrations.config_flow.error"
), ),
text: this.hass.localize( text: `${this.hass.localize(
"ui.panel.config.integrations.config_flow.could_not_load" "ui.panel.config.integrations.config_flow.could_not_load"
), )}: ${err.message || err.body}`,
}); });
return; return;
} }
@ -177,6 +176,7 @@ class DataEntryFlowDialog extends LitElement {
}); });
} }
this._loading = undefined;
this._step = undefined; this._step = undefined;
this._params = undefined; this._params = undefined;
this._devices = undefined; this._devices = undefined;
@ -372,15 +372,14 @@ class DataEntryFlowDialog extends LitElement {
try { try {
step = await this._params!.flowConfig.createFlow(this.hass, handler); step = await this._params!.flowConfig.createFlow(this.hass, handler);
} catch (err: any) { } catch (err: any) {
this._step = undefined; this.closeDialog();
this._params = undefined;
showAlertDialog(this, { showAlertDialog(this, {
title: this.hass.localize( title: this.hass.localize(
"ui.panel.config.integrations.config_flow.error" "ui.panel.config.integrations.config_flow.error"
), ),
text: this.hass.localize( text: `${this.hass.localize(
"ui.panel.config.integrations.config_flow.could_not_load" "ui.panel.config.integrations.config_flow.could_not_load"
), )}: ${err.message || err.body}`,
}); });
return; return;
} finally { } finally {
@ -405,6 +404,15 @@ class DataEntryFlowDialog extends LitElement {
this._loading = "loading_step"; this._loading = "loading_step";
try { try {
this._step = await step; 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 { } finally {
this._loading = undefined; this._loading = undefined;
} }