aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyfunkwhale/client.py13
-rw-r--r--pyfunkwhale/funkwhale.py24
2 files changed, 27 insertions, 10 deletions
diff --git a/pyfunkwhale/client.py b/pyfunkwhale/client.py
index 7343e94..347bcbb 100644
--- a/pyfunkwhale/client.py
+++ b/pyfunkwhale/client.py
@@ -96,10 +96,15 @@ class Client(object):
except FileNotFoundError:
raise InvalidTokenError(self)
- def _set_token(self, authorization_code):
+ def _set_token(self, authorization_code: str = None):
"""
Use the authorization_code to fetch the new token.
"""
+ if (
+ getattr(self, 'authorization_code', False)
+ and not authorization_code
+ ):
+ raise InvalidTokenError(self)
self.authorization_code = authorization_code
self.token = self.oauth_client.fetch_token(
@@ -122,15 +127,15 @@ class Client(object):
refresh_token=self.token["refresh_token"],
client_id=self.client_id,
client_secret=self.client_secret)
+ write_file(self.token_filename, self.token)
except InvalidScopeError:
- self._get_token()
- write_file(self.token_filename, self.token)
+ raise InvalidTokenError(self)
def _force_refresh_token(self):
"""
Force the refresh of the OAuth2 token
"""
- self._get_token()
+ self._set_token()
write_file(self.token_filename, self.token)
def _get_JWT_token(self) -> dict:
diff --git a/pyfunkwhale/funkwhale.py b/pyfunkwhale/funkwhale.py
index 47e6b84..0765dc3 100644
--- a/pyfunkwhale/funkwhale.py
+++ b/pyfunkwhale/funkwhale.py
@@ -94,8 +94,12 @@ class Funkwhale(object):
ordering_field = ['creation_date', 'id', 'name']
if ordering is not None and ordering not in ordering_field:
- raise ValueError("The ordering field {} is not in the ordering"
- "fields accepted".format(ordering))
+ raise ValueError(
+ "The ordering field '{}' is not in the ordering fields "
+ "accepted. Accepted values: {}".format(
+ ordering, ordering_field
+ )
+ )
params = self._build_params(arguments)
@@ -174,8 +178,12 @@ class Funkwhale(object):
ordering_field = ['creation_date', 'release_date', 'title']
if ordering is not None and ordering not in ordering_field:
- raise ValueError("The ordering field {} is not in the ordering"
- "fields accepted".format(ordering))
+ raise ValueError(
+ "The ordering field '{}' is not in the ordering fields "
+ "accepted. Accepted values: {}".format(
+ ordering, ordering_field
+ )
+ )
params = self._build_params(arguments)
@@ -259,8 +267,12 @@ class Funkwhale(object):
ordering_field = ['creation_date', 'release_date', 'title']
if ordering is not None and ordering not in ordering_field:
- raise ValueError("The ordering field {} is not in the ordering"
- "fields accepted".format(ordering))
+ raise ValueError(
+ "The ordering field '{}' is not in the ordering fields "
+ "accepted. Accepted values: {}".format(
+ ordering, ordering_field
+ )
+ )
params = self._build_params(arguments)