From 142cdcffcaebcc1b7ea20666180021efc1123be8 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 29 Jan 2018 12:36:58 +0100 Subject: [PATCH] Better error handling for proxy (#334) --- hassio/api/proxy.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/hassio/api/proxy.py b/hassio/api/proxy.py index 27a6c7cfc..f3ddf4b92 100644 --- a/hassio/api/proxy.py +++ b/hassio/api/proxy.py @@ -4,7 +4,7 @@ import logging import aiohttp from aiohttp import web -from aiohttp.web_exceptions import HTTPBadGateway +from aiohttp.web_exceptions import HTTPBadGateway, HTTPInternalServerError from aiohttp.hdrs import CONTENT_TYPE import async_timeout @@ -133,15 +133,19 @@ class APIProxy(CoreSysAttributes): await server.prepare(request) # handle authentication - await server.send_json({ - 'type': 'auth_required', - 'ha_version': self._homeassistant.version, - }) - await server.receive_json() # get internal token - await server.send_json({ - 'type': 'auth_ok', - 'ha_version': self._homeassistant.version, - }) + try: + await server.send_json({ + 'type': 'auth_required', + 'ha_version': self._homeassistant.version, + }) + await server.receive_json() # get internal token + await server.send_json({ + 'type': 'auth_ok', + 'ha_version': self._homeassistant.version, + }) + except RuntimeError as err: + _LOGGER.error("Can't initialize handshake: %s", err) + raise HTTPInternalServerError() from None # init connection to hass client = await self._websocket_client()