Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
fix: better auth error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sibalzer committed Oct 26, 2021
1 parent ed21a22 commit b4ac864
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions primelooter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
log = logging.getLogger()


class AuthException(Exception):
pass


class PrimeLooter():

def __init__(self, cookies, publishers='all', headless=True):
Expand Down Expand Up @@ -56,13 +60,14 @@ def auth(self) -> None:
self.page.goto('https://gaming.amazon.com/home')
response = response_info.value.json()['data']['currentUser']
if not response['isSignedIn']:
raise Exception('Authentication: Not signed in')
raise AuthException(
'Authentication: Not signed in. (Please recreate the cookie.txt file)')
elif not response['isAmazonPrime']:
raise Exception(
'Authentication: Not a valid Amazon Prime account')
raise AuthException(
'Authentication: Not a valid Amazon Prime account. (Loot can only be redeemed with an Amazon Prime Membership)')
elif not response['isTwitchPrime']:
raise Exception(
'Authentication: Not a valid Twitch Prime account')
raise AuthException(
'Authentication: Not a valid Twitch Prime account. (Loot can only be redeemed with an Amazon Prime subscription and a connected Twitch Prime account)')

def get_offers(self) -> typing.List:
with self.page.expect_response(lambda response: 'https://gaming.amazon.com/graphql' in response.url and 'primeOffers' in response.json()['data']) as response_info:
Expand Down Expand Up @@ -302,8 +307,11 @@ def read_cookiefile(path: str) -> typing.List[Cookie]:
log.info("start looting cycle")
looter.run(dump)
log.info("finished looting cycle")
except AuthException as ex:
log.error("%s", ex)
sys.exit(1)
except Exception as ex:
log.error("Error %s", ex)
log.error("%s", ex)
traceback.print_tb(ex.__traceback__)
time.sleep(60)
continue
Expand Down

0 comments on commit b4ac864

Please sign in to comment.