Actually use the unexpected_content translation;

and handle the associated exception everywhere
This commit is contained in:
DevilXD committed 2022-08-24 12:18:00 +02:00
1 parent 091ed1422c
commit 53d14d3dd7
2 files changed
+13 -19

No files matched your search

+1 -1
View File
@@ -214,7 +214,7 @@ default_translation: Translation = {
},
"login": {
"unexpected_content": (
"Unexpected content type returned instead of JSON, usually due to being redirected. "
"Unexpected content type returned, usually due to being redirected. "
"Do you need to login for internet access?"
),
"incorrect_login_pass": "Incorrect username or password.",
+12 -18
View File
@@ -165,6 +165,14 @@ class Twitch:
return 0
return self.games[game]
async def run(self):
try:
await self._run()
except ExitRequest:
pass
except aiohttp.ContentTypeError as exc:
raise MinerException(_("login", "unexpected_content")) from exc
async def _run(self):
"""
Main method that runs the whole client.
@@ -394,13 +402,6 @@ class Twitch:
break
await self._state_change.wait()
async def run(self):
try:
await self._run()
except ExitRequest:
pass
# post-main-loop code goes here
async def _watch_sleep(self, delay: float) -> None:
# we use wait_for here to allow an asyncio.sleep-like that can be ended prematurely
self._watching_restart.clear()
@@ -739,17 +740,10 @@ class Twitch:
payload.pop("authy_token", None)
payload.pop("twitchguard_code", None)
for attempt in range(2):
try:
async with self.request(
"POST", "https://passport.twitch.tv/login", json=payload
) as response:
login_response: JsonType = await response.json()
except aiohttp.ContentTypeError as exc:
raise MinerException(
"Unexpected content type returned instead of JSON, "
"usually due to being redirected. "
"Do you need to login for internet access?"
) from exc
async with self.request(
"POST", "https://passport.twitch.tv/login", json=payload
) as response:
login_response: JsonType = await response.json()
# Feed this back in to avoid running into CAPTCHA if possible
if "captcha_proof" in login_response: