Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Refactor the use of StatusCodeException #116

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/Browser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from AssertCondition import AssertCondition
from Exceptions.NoAccessTokenException import NoAccessTokenException
from Exceptions.RateLimitException import RateLimitException
from Match import Match
Expand Down Expand Up @@ -115,16 +116,18 @@ def refreshSession(self):
"""
Refresh access and entitlement tokens
"""
headers = {"Origin": "https://lolesports.com",
"Referrer": "https://lolesports.com"}
resAccessToken = self.client.get(
"https://account.rewards.lolesports.com/v1/session/refresh", headers=headers)
resAccessToken.close()
if resAccessToken.status_code == 200:
try:
headers = {"Origin": "https://lolesports.com",
"Referrer": "https://lolesports.com"}
resAccessToken = self.client.get(
"https://account.rewards.lolesports.com/v1/session/refresh", headers=headers)
AssertCondition.statusCodeMatches(200, resAccessToken)
resAccessToken.close()
self.__dumpCookies()
else:
except StatusCodeAssertException as ex:
self.log.error("Failed to refresh session")
raise StatusCodeAssertException(200, resAccessToken.status_code, resAccessToken.request.url)
self.log.error(ex)
raise ex

def maintainSession(self):
"""
Expand Down Expand Up @@ -188,11 +191,7 @@ def __sendWatch(self, match: Match):
"Referrer": "https://lolesports.com"}
res = self.client.post(
"https://rex.rewards.lolesports.com/v1/events/watch", headers=headers, json=data)
if res.status_code != 201:
statusCode = res.status_code
url = res.request.url
res.close()
raise StatusCodeAssertException(201, statusCode, url)
AssertCondition.statusCodeMatches(201, res)
res.close()

def __getLoginTokens(self, form: str) -> tuple[str, str]:
Expand Down