lvsp_conn: handle errors when connecting to voice server

This commit is contained in:
Luna 2019-03-04 01:29:14 -03:00
parent 9d80cb5564
commit 336f3a6eaf
1 changed files with 12 additions and 1 deletions

View File

@ -130,11 +130,22 @@ class LVSPConnection:
# TODO: error codes in LVSP
raise Exception('invalid op code')
async def start(self):
"""Try to start a websocket connection."""
try:
self.conn = await websockets.connect(f'wss://{self.hostname}')
except Exception as e:
log.exception('failed to start lvsp conn to {}', self.hostname)
async def run(self):
"""Start the websocket."""
self.conn = await websockets.connect(f'wss://{self.hostname}')
await self.start()
try:
if not self.conn:
log.error('failed to start lvsp connection, stopping')
return
await self._loop()
except websockets.exceptions.ConnectionClosed as err:
log.warning('conn close, {}, err={}', self._log_id, err)