Skip to content

Commit 7422d68

Browse files
fix: Handle MissingTokenError when refreshing token
1 parent b0bb798 commit 7422d68

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

fourinsight/api/authenticate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from oauthlib.oauth2 import (
1313
BackendApplicationClient,
1414
InvalidGrantError,
15+
MissingTokenError,
1516
WebApplicationClient,
1617
)
1718
from requests.adapters import HTTPAdapter
@@ -134,7 +135,7 @@ def __init__(self, client, auth_force=False, **kwargs):
134135
else:
135136
try:
136137
token = self.refresh_token()
137-
except (KeyError, ValueError, InvalidGrantError):
138+
except (KeyError, ValueError, InvalidGrantError, MissingTokenError):
138139
log.debug("not able to refresh token")
139140
token = self.fetch_token()
140141
else:

tests/test_authenticator.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def test_constants():
3232
@patch("fourinsight.api.authenticate.user_data_dir")
3333
class Test_TokenCache:
3434
def test_init_dir_doesnt_exists(self, mock_cache_dir, tmp_path):
35-
3635
cache_dir = tmp_path / "cache_dir"
3736
mock_cache_dir.return_value = cache_dir
3837

@@ -508,7 +507,6 @@ def test_request_logger(self, mock_request, mock_fetch, mock_refresh):
508507
assert log_out.startswith("request initiated")
509508

510509
def test_get_pages(self, mock_fetch, mock_refresh):
511-
512510
JSON_DATA = [
513511
{
514512
"value": {"a": 0, "b": "foo", "c": "bar"},
@@ -561,7 +559,6 @@ def get_side_effect(*args, **kwargs):
561559
)
562560

563561
def test_get_pages_last_nextlink_none(self, mock_fetch, mock_refresh):
564-
565562
JSON_DATA = [
566563
{
567564
"value": {"a": 0, "b": "foo", "c": "bar"},
@@ -615,7 +612,6 @@ def get_side_effect(*args, **kwargs):
615612
)
616613

617614
def test_get_pages_raises_json_list(self, mock_fetch, mock_refresh):
618-
619615
JSON_DATA = [
620616
{
621617
"a": "foo",
@@ -643,7 +639,6 @@ def test_get_pages_raises_json_list(self, mock_fetch, mock_refresh):
643639
next(pages)
644640

645641
def test_get_pages_raise_for_status(self, mock_fetch, mock_refresh):
646-
647642
JSON_DATA = [
648643
{
649644
"value": {"a": 0, "b": "foo", "c": "bar"},

0 commit comments

Comments
 (0)