Exit if initial token request fails for Revolut
This commit is contained in:
parent
0c9fadbdf6
commit
3c7a6685b4
|
@ -105,7 +105,7 @@ def start(handler, refresh_sec):
|
||||||
if settings.Revolut.SetupToken == "1":
|
if settings.Revolut.SetupToken == "1":
|
||||||
deferLater(reactor, 1, handler.setup_auth)
|
deferLater(reactor, 1, handler.setup_auth)
|
||||||
else:
|
else:
|
||||||
deferLater(reactor, 1, handler.get_new_token)
|
deferLater(reactor, 1, handler.get_new_token, True)
|
||||||
deferLater(reactor, 4, handler.setup_webhook)
|
deferLater(reactor, 4, handler.setup_webhook)
|
||||||
lc = LoopingCall(handler.get_new_token)
|
lc = LoopingCall(handler.get_new_token)
|
||||||
lc.start(refresh_sec)
|
lc.start(refresh_sec)
|
||||||
|
|
|
@ -56,6 +56,7 @@ class Revolut(object):
|
||||||
try:
|
try:
|
||||||
parsed = r.json()
|
parsed = r.json()
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
|
self.log.error("Error parsing access token response: {content}", content=r.content)
|
||||||
return False
|
return False
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
try:
|
try:
|
||||||
|
@ -72,7 +73,7 @@ class Revolut(object):
|
||||||
self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed)
|
self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_new_token(self):
|
def get_new_token(self, fail=False):
|
||||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||||
data = {
|
data = {
|
||||||
"grant_type": "refresh_token",
|
"grant_type": "refresh_token",
|
||||||
|
@ -85,6 +86,8 @@ class Revolut(object):
|
||||||
try:
|
try:
|
||||||
parsed = r.json()
|
parsed = r.json()
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
|
if fail:
|
||||||
|
exit()
|
||||||
return False
|
return False
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
if "access_token" in parsed.keys():
|
if "access_token" in parsed.keys():
|
||||||
|
@ -93,9 +96,13 @@ class Revolut(object):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.log.error(f"Token refresh didn't contain access token: {parsed}", parsed=parsed)
|
self.log.error(f"Token refresh didn't contain access token: {parsed}", parsed=parsed)
|
||||||
|
if fail:
|
||||||
|
exit()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed)
|
self.log.error(f"Cannot refresh token: {parsed}", parsed=parsed)
|
||||||
|
if fail:
|
||||||
|
exit()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def setup_webhook(self):
|
def setup_webhook(self):
|
||||||
|
@ -121,3 +128,6 @@ class Revolut(object):
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
parsed = r.json()
|
parsed = r.json()
|
||||||
return parsed
|
return parsed
|
||||||
|
else:
|
||||||
|
self.log.error("Cannot get webhooks: {content}", r.content)
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue