From 1dac01b1415263c4371a1918828ef2fd4cc39e40 Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Mon, 30 Dec 2024 22:20:24 +0100 Subject: [PATCH] Make the GQL claim operation treat request errors as a failed claiming operation --- inventory.py | 14 ++++++++++---- twitch.py | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/inventory.py b/inventory.py index 0b7ac8de..30ba9be6 100644 --- a/inventory.py +++ b/inventory.py @@ -8,6 +8,7 @@ from datetime import datetime, timedelta, timezone from channel import Channel +from exceptions import GQLException from constants import GQL_OPERATIONS, URLType from utils import timestamp, invalidate_cache, Game @@ -155,11 +156,16 @@ async def _claim(self) -> bool: return True if not self.can_claim: return False - response = await self._twitch.gql_request( - GQL_OPERATIONS["ClaimDrop"].with_variables( - {"input": {"dropInstanceID": self.claim_id}} + try: + response = await self._twitch.gql_request( + GQL_OPERATIONS["ClaimDrop"].with_variables( + {"input": {"dropInstanceID": self.claim_id}} + ) ) - ) + except GQLException: + # regardless of the error, we have to assume + # the claiming operation has potentially failed + return False data = response["data"] if "errors" in data and data["errors"]: return False diff --git a/twitch.py b/twitch.py index d7f59336..28056373 100644 --- a/twitch.py +++ b/twitch.py @@ -1179,7 +1179,7 @@ async def process_drops(self, user_id: int, message: JsonType): self.print(_("status", "claimed_drop").format(drop=claim_text.replace('\n', ' '))) self.gui.tray.notify(claim_text, _("gui", "tray", "notification_title")) else: - logger.error(f"Drop claim failed! Drop ID: {drop_id}") + logger.error(f"Drop claim has potentially failed! Drop ID: {drop_id}") # About 4-20s after claiming the drop, next drop can be started # by re-sending the watch payload. We can test for it by fetching the current drop # via GQL, and then comparing drop IDs.