From 3c7a6685b4155b049c2b3c05fe2308164dfa593f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 26 Dec 2021 23:11:48 +0000 Subject: [PATCH] Exit if initial token request fails for Revolut --- handler/app.py | 2 +- handler/revolut.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/handler/app.py b/handler/app.py index 008b7f9..703066f 100755 --- a/handler/app.py +++ b/handler/app.py @@ -105,7 +105,7 @@ def start(handler, refresh_sec): if settings.Revolut.SetupToken == "1": deferLater(reactor, 1, handler.setup_auth) else: - deferLater(reactor, 1, handler.get_new_token) + deferLater(reactor, 1, handler.get_new_token, True) deferLater(reactor, 4, handler.setup_webhook) lc = LoopingCall(handler.get_new_token) lc.start(refresh_sec) diff --git a/handler/revolut.py b/handler/revolut.py index bcbdc67..754d589 100644 --- a/handler/revolut.py +++ b/handler/revolut.py @@ -56,6 +56,7 @@ class Revolut(object): try: parsed = r.json() except JSONDecodeError: + self.log.error("Error parsing access token response: {content}", content=r.content) return False if r.status_code == 200: try: @@ -72,7 +73,7 @@ class Revolut(object): self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed) return False - def get_new_token(self): + def get_new_token(self, fail=False): headers = {"Content-Type": "application/x-www-form-urlencoded"} data = { "grant_type": "refresh_token", @@ -85,6 +86,8 @@ class Revolut(object): try: parsed = r.json() except JSONDecodeError: + if fail: + exit() return False if r.status_code == 200: if "access_token" in parsed.keys(): @@ -93,9 +96,13 @@ class Revolut(object): return True else: self.log.error(f"Token refresh didn't contain access token: {parsed}", parsed=parsed) + if fail: + exit() return False else: self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed) + if fail: + exit() return False def setup_webhook(self): @@ -121,3 +128,6 @@ class Revolut(object): if r.status_code == 200: parsed = r.json() return parsed + else: + self.log.error("Cannot get webhooks: {content}", r.content) + return False