Better error handling for proxy
@@ -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,6 +133,7 @@ class APIProxy(CoreSysAttributes):
await server.prepare(request)
# handle authentication
+ try:
await server.send_json({
'type': 'auth_required',
'ha_version': self._homeassistant.version,
@@ -142,6 +143,9 @@ class APIProxy(CoreSysAttributes):
'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()
