Skip to content

Commit 08edb38

Browse files
author
Pegasus
committed
Raise Token expired exception
1 parent 7faf878 commit 08edb38

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

td/client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
from td.oauth import run
2222
from td.oauth import shutdown
2323

24+
class TknExpError(Exception):
25+
"""Raise exception when refresh or access token is expired.
26+
27+
Args:
28+
Exception (Exception): The base python exception class
29+
"""
30+
def __init__(self, message):
31+
"""Print out message for this exception.
32+
33+
Args:
34+
message (str): Pass in the message returned by the server.
35+
"""
36+
self.message = message
37+
super().__init__(self.message)
2438

2539
class TDClient():
2640

@@ -569,6 +583,9 @@ def _make_request(self, method: str, endpoint: str, mode: str = None, params: di
569583
print("RESPONSE TEXT: {text}".format(text=response.text))
570584
print('-'*80)
571585

586+
if response.status_code == 401:
587+
raise TknExpError(message=response.text)
588+
572589
def _validate_arguments(self, endpoint: str, parameter_name: str, parameter_argument: List[str]) -> bool:
573590
"""Validates arguments for an API call.
574591

0 commit comments

Comments
 (0)