Skip to content

Commit f6ab265

Browse files
pull out new error. It causes downstream errors, and was only added in an attempt to give better errors, not change behavior. (#29)
* was this it? * testing * break, again. * pull out new error. It causes downstream errors, and was only added in an attempt to give better errors, not change behavior.
1 parent 6ef37b9 commit f6ab265

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/planet_auth/oidc/request_authenticator.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from typing import Dict, Optional
1818

1919
import planet_auth.logging.auth_logger
20-
from planet_auth import AuthException
2120
from planet_auth.credential import Credential
2221
from planet_auth.request_authenticator import CredentialRequestAuthenticator
2322
from planet_auth.oidc.auth_client import OidcAuthClient
@@ -114,20 +113,28 @@ def _refresh_if_needed(self):
114113
self._load()
115114
except Exception as e: # pylint: disable=broad-exception-caught
116115
auth_logger.warning(
117-
msg="Error loading auth token. Continuing with old auth token. Load error: " + str(e)
116+
msg=f"Error loading auth token. Continuing with old configuration and token data. Load error: {str(e)}"
118117
)
119118
if now > self._refresh_at:
120119
try:
121120
self._refresh()
122121
except Exception as e: # pylint: disable=broad-exception-caught
123122
auth_logger.warning(
124-
msg="Error refreshing auth token. Continuing with old auth token. Refresh error: " + str(e)
123+
msg=f"Error obtaining new or refreshed auth token. Continuing with old configuration and token data. Refresh error: {str(e)}"
125124
)
126125

127-
if not (self._credential and self._credential.is_loaded()):
128-
# "refresh" may also be called to initialize in some cases, as in client credentials flow.
129-
# Continuing with what we have is not an option when we have nothing.
130-
raise AuthException("Failed to load or obtain a valid access token.")
126+
# This tries to give a client a better error when there is no old
127+
# token to fall back to. But, it is known to cause problems when
128+
# auth truly isn't needed, either because the service does not need
129+
# it or because it has been mocked out (as in unit test cases).
130+
# So, we rely on the warnings to keep the user informed. This might
131+
# also result in the user seeing errors from the server - the quality
132+
# of which we have no control over.
133+
#
134+
# if not (self._credential and self._credential.is_loaded()):
135+
# # "refresh" may also be called to initialize in some cases, as in client credentials flow.
136+
# # Continuing with what we have is not an option when we have nothing.
137+
# raise AuthException("Failed to load or obtain a valid access token.")
131138

132139
def pre_request_hook(self):
133140
self._refresh_if_needed()

0 commit comments

Comments
 (0)