Skip to content

Commit

Permalink
Merge pull request #99 from dule1322/hotfix-retry
Browse files Browse the repository at this point in the history
Hotfix: API token refresh infinite recursion fix if refresh token is invalid/expired
  • Loading branch information
igorperic17 authored Dec 1, 2023
2 parents 0a0de91 + a818c5d commit 4d9b16a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions coretex/networking/network_manager_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def request(
headers = headers
)

response = NetworkResponse(rawResponse)
response = NetworkResponse(rawResponse, endpoint)
if response.hasFailed():
logRequestFailure(endpoint, response)

Expand Down Expand Up @@ -569,7 +569,8 @@ def shouldRetry(self, retryCount: int, response: Optional[NetworkResponse]) -> b

if response is not None:
# If we get unauthorized maybe API token is expired
if response.isUnauthorized():
# If refresh endpoint failed with unauthorized do not retry
if response.isUnauthorized() and response.endpoint != REFRESH_ENDPOINT:
refreshTokenResponse = self.refreshToken()
return not refreshTokenResponse.hasFailed()

Expand Down
5 changes: 4 additions & 1 deletion coretex/networking/network_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ class NetworkResponse:
----------
response : Response
python.requests HTTP reponse
endpoint : str
endpoint to which the request was sent
"""

def __init__(self, response: Response):
def __init__(self, response: Response, endpoint: str):
self._raw = response
self.endpoint = endpoint

@property
def statusCode(self) -> int:
Expand Down

0 comments on commit 4d9b16a

Please sign in to comment.