(profiles): Improve logging and error handling.
This commit is contained in:
@@ -71,7 +71,8 @@ class TwitchLinkStatic(LeoUI):
|
|||||||
def embed(self, value):
|
def embed(self, value):
|
||||||
self._embed = value
|
self._embed = value
|
||||||
|
|
||||||
@button(label="Link", custom_id="BTN-LINK-TWITCH", style=ButtonStyle.green, emoji='🔗')
|
@button(label="Connect", custom_id="BTN-LINK-TWITCH", style=ButtonStyle.green, emoji='🔗')
|
||||||
|
@log_wrap(action="link-twitch-btn")
|
||||||
async def button_linker(self, interaction: discord.Interaction, btn: Button):
|
async def button_linker(self, interaction: discord.Interaction, btn: Button):
|
||||||
# Here we just reply to the interaction with the AuthFlow UI
|
# Here we just reply to the interaction with the AuthFlow UI
|
||||||
# TODO
|
# TODO
|
||||||
@@ -116,7 +117,9 @@ class TwitchLinkFlow(MessageUI):
|
|||||||
# This can happen if starting the flow failed
|
# This can happen if starting the flow failed
|
||||||
await self.close()
|
await self.close()
|
||||||
|
|
||||||
|
@log_wrap(action="start-twitch-flow-ui")
|
||||||
async def _start_flow(self):
|
async def _start_flow(self):
|
||||||
|
logger.info(f"Starting twitch authentication flow for {self.user}")
|
||||||
try:
|
try:
|
||||||
self.flow = await self.bot.get_cog('TwitchAuthCog').start_auth()
|
self.flow = await self.bot.get_cog('TwitchAuthCog').start_auth()
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
@@ -130,6 +133,7 @@ class TwitchLinkFlow(MessageUI):
|
|||||||
self._stage = FlowState.WAITING
|
self._stage = FlowState.WAITING
|
||||||
self._auth_task = asyncio.create_task(self._auth_flow())
|
self._auth_task = asyncio.create_task(self._auth_flow())
|
||||||
|
|
||||||
|
@log_wrap(action="run-twitch-flow-ui")
|
||||||
async def _auth_flow(self):
|
async def _auth_flow(self):
|
||||||
"""
|
"""
|
||||||
Run the flow and wait for a timeout, cancellation, or callback.
|
Run the flow and wait for a timeout, cancellation, or callback.
|
||||||
@@ -138,12 +142,12 @@ class TwitchLinkFlow(MessageUI):
|
|||||||
assert self.flow is not None
|
assert self.flow is not None
|
||||||
try:
|
try:
|
||||||
# TODO: Cancel this in cleanup
|
# TODO: Cancel this in cleanup
|
||||||
authrow = await asyncio.wait_for(self.flow.run(), timeout=180)
|
authrow = await asyncio.wait_for(self.flow.run(), timeout=60)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
self._stage = FlowState.TIMEOUT
|
self._stage = FlowState.TIMEOUT
|
||||||
# Link Timed Out!
|
# Link Timed Out!
|
||||||
self._info = (
|
self._info = (
|
||||||
"We didn't receive a response for three minutes so we closed the uplink "
|
"We didn't receive a response so we closed the uplink "
|
||||||
"to keep your account safe! If you still want to connect, please try again!"
|
"to keep your account safe! If you still want to connect, please try again!"
|
||||||
)
|
)
|
||||||
await self.refresh()
|
await self.refresh()
|
||||||
@@ -161,6 +165,8 @@ class TwitchLinkFlow(MessageUI):
|
|||||||
self._stage = FlowState.CANCELLED
|
self._stage = FlowState.CANCELLED
|
||||||
await self.refresh()
|
await self.refresh()
|
||||||
await self.close()
|
await self.close()
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Something unexpected went wrong while running the flow!")
|
||||||
else:
|
else:
|
||||||
self._stage = FlowState.WORKING
|
self._stage = FlowState.WORKING
|
||||||
self._info = (
|
self._info = (
|
||||||
@@ -265,7 +271,7 @@ class TwitchLinkFlow(MessageUI):
|
|||||||
|
|
||||||
if self._stage is FlowState.WAITING:
|
if self._stage is FlowState.WAITING:
|
||||||
# Message should be the initial request page
|
# Message should be the initial request page
|
||||||
dur = discord.utils.format_dt(utc_now() + timedelta(seconds=179), style='R')
|
dur = discord.utils.format_dt(utc_now() + timedelta(seconds=60), style='R')
|
||||||
|
|
||||||
title = "Press the button to login!"
|
title = "Press the button to login!"
|
||||||
desc = (
|
desc = (
|
||||||
|
|||||||
Reference in New Issue
Block a user