Skip to content

Commit

Permalink
Single-retry PersistedQueryNotFound as well
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Jan 5, 2025
1 parent 1f49ee9 commit 689afdd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,8 @@ async def gql_request(
) -> JsonType | list[JsonType]:
gql_logger.debug(f"GQL Request: {ops}")
backoff = ExponentialBackoff(maximum=60)
# Use a flag to retry the request a single time, if a "service error" is encountered
service_error_retry: bool = True
# Use a flag to retry the request a single time, if a specific set of errors is encountered
single_retry: bool = True
for delay in backoff:
async with self._qgl_limiter:
auth_state = await self.get_auth()
Expand All @@ -1377,20 +1377,27 @@ async def gql_request(
if "errors" in response_json:
for error_dict in response_json["errors"]:
if "message" in error_dict:
if error_dict["message"] == "service error" and service_error_retry:
if (
single_retry
and error_dict["message"] in (
"service error"
"PersistedQueryNotFound"
)
):
logger.error(
"Retrying a \"service error\" for "
f"Retrying a {error_dict['message']} for "
f"{response_json['extensions']['operationName']}"
)
service_error_retry = False
delay = 5 # overwrite delay
single_retry = False
if delay < 5:
# overwrite the delay if too short
delay = 5
force_retry = True
break
elif (
error_dict["message"] in (
# "server error",
"service unavailable",
"service timeout",
"service unavailable",
"context deadline exceeded",
)
):
Expand Down

0 comments on commit 689afdd

Please sign in to comment.