Cast: Show error message instead of number (#3752)

* Cast: Show error message instead of number

* Update hc-main.ts
This commit is contained in:
Bram Kragten 2019-09-18 18:33:58 +02:00 committed by Paulus Schoutsen
parent 0bfc61629e
commit b6fbf4da3a

View File

@ -137,14 +137,14 @@ export class HcMain extends HassElement {
}),
});
} catch (err) {
this._error = err;
this._error = this._getErrorMessage(err);
return;
}
let connection;
try {
connection = await createConnection({ auth });
} catch (err) {
this._error = err;
this._error = this._getErrorMessage(err);
return;
}
if (this.hass) {
@ -213,6 +213,23 @@ export class HcMain extends HassElement {
});
}
private _getErrorMessage(error: number): string {
switch (error) {
case 1:
return "Unable to connect to the Home Assistant websocket API.";
case 2:
return "The supplied authentication is invalid.";
case 3:
return "The connection to Home Assistant was lost.";
case 4:
return "Missing hassUrl. This is required.";
case 5:
return "Home Assistant needs to be served over https:// to use with Home Assistant Cast.";
default:
return "Unknown Error";
}
}
private _breakFree() {
const controls = document.body.querySelector("touch-controls");
if (controls) {