mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 05:16:34 +00:00
Send error message to sender (#10660)
This commit is contained in:
parent
5304e5a670
commit
96f103644a
@ -13,7 +13,11 @@ import {
|
|||||||
ShowDemoMessage,
|
ShowDemoMessage,
|
||||||
ShowLovelaceViewMessage,
|
ShowLovelaceViewMessage,
|
||||||
} from "../../../../src/cast/receiver_messages";
|
} from "../../../../src/cast/receiver_messages";
|
||||||
import { ReceiverStatusMessage } from "../../../../src/cast/sender_messages";
|
import {
|
||||||
|
ReceiverErrorCode,
|
||||||
|
ReceiverErrorMessage,
|
||||||
|
ReceiverStatusMessage,
|
||||||
|
} from "../../../../src/cast/sender_messages";
|
||||||
import { atLeastVersion } from "../../../../src/common/config/version";
|
import { atLeastVersion } from "../../../../src/common/config/version";
|
||||||
import { isNavigationClick } from "../../../../src/common/dom/is-navigation-click";
|
import { isNavigationClick } from "../../../../src/common/dom/is-navigation-click";
|
||||||
import {
|
import {
|
||||||
@ -134,6 +138,26 @@ export class HcMain extends HassElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _sendError(
|
||||||
|
error_code: number,
|
||||||
|
error_message: string,
|
||||||
|
senderId?: string
|
||||||
|
) {
|
||||||
|
const error: ReceiverErrorMessage = {
|
||||||
|
type: "receiver_error",
|
||||||
|
error_code,
|
||||||
|
error_message,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (senderId) {
|
||||||
|
this.sendMessage(senderId, error);
|
||||||
|
} else {
|
||||||
|
for (const sender of castContext.getSenders()) {
|
||||||
|
this.sendMessage(sender.id, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _dialogClosed = () => {
|
private _dialogClosed = () => {
|
||||||
document.body.setAttribute("style", "overflow-y: auto !important");
|
document.body.setAttribute("style", "overflow-y: auto !important");
|
||||||
};
|
};
|
||||||
@ -156,14 +180,18 @@ export class HcMain extends HassElement {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._error = this._getErrorMessage(err);
|
const errorMessage = this._getErrorMessage(err);
|
||||||
|
this._error = errorMessage;
|
||||||
|
this._sendError(err, errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let connection;
|
let connection;
|
||||||
try {
|
try {
|
||||||
connection = await createConnection({ auth });
|
connection = await createConnection({ auth });
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._error = this._getErrorMessage(err);
|
const errorMessage = this._getErrorMessage(err);
|
||||||
|
this._error = errorMessage;
|
||||||
|
this._sendError(err, errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
@ -181,8 +209,10 @@ export class HcMain extends HassElement {
|
|||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
this._sendStatus(msg.senderId!);
|
this._sendStatus(msg.senderId!);
|
||||||
this._error = "Cannot show Lovelace because we're not connected.";
|
this._error = "Cannot show Lovelace because we're not connected.";
|
||||||
|
this._sendError(ReceiverErrorCode.NOT_CONNECTED, this._error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._error = undefined;
|
||||||
if (msg.urlPath === "lovelace") {
|
if (msg.urlPath === "lovelace") {
|
||||||
msg.urlPath = null;
|
msg.urlPath = null;
|
||||||
}
|
}
|
||||||
@ -204,10 +234,14 @@ export class HcMain extends HassElement {
|
|||||||
this._handleNewLovelaceConfig(lovelaceConfig)
|
this._handleNewLovelaceConfig(lovelaceConfig)
|
||||||
);
|
);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "config_not_found") {
|
if (
|
||||||
|
atLeastVersion(this.hass.connection.haVersion, 0, 107) &&
|
||||||
|
err.code !== "config_not_found"
|
||||||
|
) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log("Error fetching Lovelace configuration", err, msg);
|
console.log("Error fetching Lovelace configuration", err, msg);
|
||||||
this._error = `Error fetching Lovelace configuration: ${err.message}`;
|
this._error = `Error fetching Lovelace configuration: ${err.message}`;
|
||||||
|
this._sendError(ReceiverErrorCode.FETCH_CONFIG_FAILED, this._error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Generate a Lovelace config.
|
// Generate a Lovelace config.
|
||||||
|
@ -11,4 +11,20 @@ export interface ReceiverStatusMessage extends BaseCastMessage {
|
|||||||
urlPath?: string | null;
|
urlPath?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ReceiverErrorMessage extends BaseCastMessage {
|
||||||
|
type: "receiver_error";
|
||||||
|
error_code: ReceiverErrorCode;
|
||||||
|
error_message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const enum ReceiverErrorCode {
|
||||||
|
CONNECTION_FAILED = 1,
|
||||||
|
AUTHENTICATION_FAILED = 2,
|
||||||
|
CONNECTION_LOST = 3,
|
||||||
|
HASS_URL_MISSING = 4,
|
||||||
|
NO_HTTPS = 5,
|
||||||
|
NOT_CONNECTED = 21,
|
||||||
|
FETCH_CONFIG_FAILED = 22,
|
||||||
|
}
|
||||||
|
|
||||||
export type SenderMessage = ReceiverStatusMessage;
|
export type SenderMessage = ReceiverStatusMessage;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user