improve error message for OAuth2 authentication
This commit is contained in:
parent
7f4e41c989
commit
4313c95bc9
@ -561,10 +561,11 @@ class DeviantartAPI():
|
||||
|
||||
auth = (self.client_id, self.client_secret)
|
||||
response = self.session.post(url, data=data, auth=auth)
|
||||
if response.status_code != 200:
|
||||
raise exception.AuthenticationError()
|
||||
|
||||
data = response.json()
|
||||
|
||||
if response.status_code != 200:
|
||||
raise exception.AuthenticationError('"{} ({})"'.format(
|
||||
data.get("error_description"), data.get("error")))
|
||||
if refresh_token:
|
||||
_refresh_token_cache.invalidate(refresh_token)
|
||||
_refresh_token_cache(refresh_token, data["refresh_token"])
|
||||
|
@ -216,7 +216,7 @@ class RedditAPI():
|
||||
"""Actual authenticate implementation"""
|
||||
url = "https://www.reddit.com/api/v1/access_token"
|
||||
if refresh_token:
|
||||
self.log.info("Refreshing access token")
|
||||
self.log.info("Refreshing private access token")
|
||||
data = {"grant_type": "refresh_token",
|
||||
"refresh_token": refresh_token}
|
||||
else:
|
||||
@ -226,7 +226,8 @@ class RedditAPI():
|
||||
"device_id": "DO_NOT_TRACK_THIS_DEVICE"}
|
||||
response = self.session.post(url, data=data, auth=(self.client_id, ""))
|
||||
if response.status_code != 200:
|
||||
raise exception.AuthenticationError()
|
||||
raise exception.AuthenticationError('"{} ({})"'.format(
|
||||
response.json().get("message"), response.status_code))
|
||||
return "Bearer " + response.json()["access_token"]
|
||||
|
||||
def _call(self, endpoint, params):
|
||||
|
@ -63,9 +63,9 @@ class Job():
|
||||
log = self.extractor.log
|
||||
for msg in self.extractor:
|
||||
self.dispatch(msg)
|
||||
except exception.AuthenticationError:
|
||||
log.error("Authentication failed. Please provide a valid "
|
||||
"username/password pair.")
|
||||
except exception.AuthenticationError as exc:
|
||||
msg = str(exc) or "Please provide a valid username/password pair."
|
||||
log.error("Authentication failed: %s", msg)
|
||||
except exception.AuthorizationError:
|
||||
log.error("You do not have permission to access the resource "
|
||||
"at '%s'", self.url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user