1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-22 20:00:29 +03:00

CAPI: Actually try to use Refresh Token if CAPI says unauthorized

The refactor for threaded CAPI worker has inadvertently caused us to
always try *full* re-auth when the CAPI signals the Access Token is
expired.
This commit is contained in:
Athanasius 2021-11-05 17:52:50 +00:00
parent 1e00b64bc3
commit 8e32ecd216
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D
2 changed files with 17 additions and 0 deletions

View File

@ -1159,6 +1159,13 @@ class AppWindow(object):
# LANG: Frontier CAPI server error when fetching data
self.status['text'] = _('Frontier CAPI server error')
except companion.CredentialsRequireRefresh:
# LANG: Frontier CAPI Access Token expired, trying to get a new one
self.status['text'] = _('CAPI: Refreshing access token...')
if companion.session.login():
logger.debug('Initial query failed, but login() just worked, trying again...')
companion.session.retrying = True
except companion.CredentialsError:
companion.session.retrying = False
companion.session.invalidate()

View File

@ -265,6 +265,15 @@ class CredentialsError(Exception):
self.args = (_('Error: Invalid Credentials'),)
class CredentialsRequireRefresh(Exception):
"""Exception Class for CAPI credentials requiring refresh."""
def __init__(self, *args) -> None:
self.args = args
if not args:
self.args = ('CAPI: Requires refresh of Access Token',)
class CmdrError(Exception):
"""Exception Class for CAPI Commander error.
@ -772,6 +781,7 @@ class Session(object):
self.dump(r)
if r.status_code == 401: # CAPI doesn't think we're Auth'd
# TODO: This needs to try a REFRESH, not a full re-auth
# No need for translation, we'll go straight into trying new Auth
# and thus any message would be overwritten.
raise CredentialsError('Frontier CAPI said Auth required') from e