From b6fbf4da3abbee4ff9c84f397e9d2d7559fdd168 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 18 Sep 2019 18:33:58 +0200 Subject: [PATCH] Cast: Show error message instead of number (#3752) * Cast: Show error message instead of number * Update hc-main.ts --- cast/src/receiver/layout/hc-main.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cast/src/receiver/layout/hc-main.ts b/cast/src/receiver/layout/hc-main.ts index 63f0b30fc7..ccb20f5aa5 100644 --- a/cast/src/receiver/layout/hc-main.ts +++ b/cast/src/receiver/layout/hc-main.ts @@ -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) {