Skip to content

Commit

Permalink
propagate authentication errors to end user
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmTomahawkx committed Oct 23, 2022
1 parent 1c7a29d commit 2623d39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions twitchio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import sys
from typing import Union, Callable, List, Optional, Tuple, Any, Coroutine, Dict

from twitchio.errors import HTTPException
from twitchio.errors import HTTPException, AuthenticationError
from . import models
from .websocket import WSConnection
from .http import TwitchHTTP
Expand Down Expand Up @@ -155,7 +155,8 @@ def run(self):
connects to the twitch IRC server, and cleans up when done.
"""
try:
self.loop.create_task(self.connect())
task = self.loop.create_task(self.connect())
self.loop.run_until_complete(task) # this'll raise if the connect fails
self.loop.run_forever()
except KeyboardInterrupt:
pass
Expand Down
7 changes: 6 additions & 1 deletion twitchio/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ async def _connect(self):
if self.is_alive:
await self._websocket.close() # If for some reason we are in a weird state, close it before retrying.
if not self._client._http.nick:
data = await self._client._http.validate(token=self._token)
try:
data = await self._client._http.validate(token=self._token)
except AuthenticationError:
await self._client._http.session.close()
self._client._closing.set() # clean up and error out (this is called to avoid calling Client.close in start()
raise
self.nick = data["login"]
self.user_id = int(data["user_id"])
else:
Expand Down

0 comments on commit 2623d39

Please sign in to comment.