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:
parent
1e00b64bc3
commit
8e32ecd216
@ -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()
|
||||
|
10
companion.py
10
companion.py
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user