Skip to content

Commit

Permalink
handle expired token errors properly
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling committed Oct 15, 2024
1 parent c32ff39 commit d69f68c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def __init__(self, sub_page_size=4000, tcp_limit=5, existing_session=None, **kwa
def _token_request(self, payload):
response = requests.post(self.token_url, data=payload)
if response.ok:
self.auth = json.loads(response.text)
self.auth = response.json()
expires_in = int(self.auth["expires_in"]) - 5 * 60
self.auth_expires = pytz.utc.localize(datetime.datetime.utcnow()) + datetime.timedelta(seconds=expires_in)
return True

self.auth = None
self.auth_expires = pytz.utc.localize(datetime.datetime.min)
raise ERClientNotFound(json.loads(response.text)["error_description"])
raise ERClientNotFound(response.json().get("error_description", "invalid token"))

"""
GET Functions
Expand Down

0 comments on commit d69f68c

Please sign in to comment.