Skip to content

Commit 2623d39

Browse files
committed
propagate authentication errors to end user
1 parent 1c7a29d commit 2623d39

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

twitchio/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import sys
3131
from typing import Union, Callable, List, Optional, Tuple, Any, Coroutine, Dict
3232

33-
from twitchio.errors import HTTPException
33+
from twitchio.errors import HTTPException, AuthenticationError
3434
from . import models
3535
from .websocket import WSConnection
3636
from .http import TwitchHTTP
@@ -155,7 +155,8 @@ def run(self):
155155
connects to the twitch IRC server, and cleans up when done.
156156
"""
157157
try:
158-
self.loop.create_task(self.connect())
158+
task = self.loop.create_task(self.connect())
159+
self.loop.run_until_complete(task) # this'll raise if the connect fails
159160
self.loop.run_forever()
160161
except KeyboardInterrupt:
161162
pass

twitchio/websocket.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ async def _connect(self):
122122
if self.is_alive:
123123
await self._websocket.close() # If for some reason we are in a weird state, close it before retrying.
124124
if not self._client._http.nick:
125-
data = await self._client._http.validate(token=self._token)
125+
try:
126+
data = await self._client._http.validate(token=self._token)
127+
except AuthenticationError:
128+
await self._client._http.session.close()
129+
self._client._closing.set() # clean up and error out (this is called to avoid calling Client.close in start()
130+
raise
126131
self.nick = data["login"]
127132
self.user_id = int(data["user_id"])
128133
else:

0 commit comments

Comments
 (0)