Skip to content

Commit

Permalink
Make the GQL claim operation treat request errors as a failed claimin…
Browse files Browse the repository at this point in the history
…g operation
  • Loading branch information
DevilXD committed Dec 30, 2024
1 parent 99359a7 commit 1dac01b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1dac01b

Please sign in to comment.