mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
More error handling for preview flow (#25611)
* More error handling for preview flow * await unsub
This commit is contained in:
parent
38f8c804af
commit
e8fc36026a
@ -6,6 +6,7 @@ const HAS_CUSTOM_PREVIEW = ["generic_camera", "template"];
|
||||
export interface GenericPreview {
|
||||
state: string;
|
||||
attributes: Record<string, any>;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export const subscribePreviewGeneric = (
|
||||
|
@ -58,6 +58,11 @@ export class FlowPreviewGeneric extends LitElement {
|
||||
}
|
||||
|
||||
private _setPreview = (preview: GenericPreview) => {
|
||||
if (preview.error) {
|
||||
this._error = preview.error;
|
||||
this._preview = undefined;
|
||||
return;
|
||||
}
|
||||
const now = new Date().toISOString();
|
||||
this._preview = {
|
||||
entity_id: `${this.stepId}.___flow_preview___`,
|
||||
@ -80,6 +85,7 @@ export class FlowPreviewGeneric extends LitElement {
|
||||
if (this.flowType !== "config_flow" && this.flowType !== "options_flow") {
|
||||
return;
|
||||
}
|
||||
this._error = undefined;
|
||||
try {
|
||||
this._unsub = subscribePreviewGeneric(
|
||||
this.hass,
|
||||
@ -89,6 +95,7 @@ export class FlowPreviewGeneric extends LitElement {
|
||||
this.stepData,
|
||||
this._setPreview
|
||||
);
|
||||
await this._unsub;
|
||||
fireEvent(this, "set-flow-errors", { errors: {} });
|
||||
} catch (err: any) {
|
||||
if (typeof err.message === "string") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user