Add error classes for apiclient.discovery and apiclient.oauth
This commit is contained in:
@@ -45,13 +45,21 @@ except ImportError: # pragma: no cover
|
||||
import json as simplejson
|
||||
|
||||
|
||||
class HttpError(Exception):
|
||||
class Error(Exception):
|
||||
"""Base error for this module."""
|
||||
pass
|
||||
|
||||
|
||||
class UnknownLinkType(Exception):
|
||||
class HttpError(Error):
|
||||
"""HTTP data was invalid or unexpected."""
|
||||
pass
|
||||
|
||||
|
||||
class UnknownLinkType(Error):
|
||||
"""Link type unknown or unexpected."""
|
||||
pass
|
||||
|
||||
|
||||
DISCOVERY_URI = ('http://www.googleapis.com/discovery/0.1/describe'
|
||||
'{?api,apiVersion}')
|
||||
|
||||
|
@@ -21,7 +21,17 @@ except ImportError:
|
||||
from cgi import parse_qs, parse_qsl
|
||||
|
||||
|
||||
class MissingParameter(Exception):
|
||||
class Error(Exception):
|
||||
"""Base error for this module."""
|
||||
pass
|
||||
|
||||
|
||||
class RequestError(Error):
|
||||
"""Error occurred during request."""
|
||||
pass
|
||||
|
||||
|
||||
class MissingParameter(Error):
|
||||
pass
|
||||
|
||||
|
||||
@@ -185,7 +195,7 @@ class FlowThreeLegged(object):
|
||||
body=body)
|
||||
if resp['status'] != '200':
|
||||
logging.error('Failed to retrieve temporary authorization: %s' % content)
|
||||
raise Exception('Invalid response %s.' % resp['status'])
|
||||
raise RequestError('Invalid response %s.' % resp['status'])
|
||||
|
||||
self.request_token = dict(parse_qsl(content))
|
||||
|
||||
@@ -222,7 +232,7 @@ class FlowThreeLegged(object):
|
||||
resp, content = client.request(uri, 'POST', headers=headers)
|
||||
if resp['status'] != '200':
|
||||
logging.error('Failed to retrieve access token: %s' % content)
|
||||
raise Exception('Invalid response %s.' % resp['status'])
|
||||
raise RequestError('Invalid response %s.' % resp['status'])
|
||||
|
||||
oauth_params = dict(parse_qsl(content))
|
||||
token = oauth.Token(
|
||||
|
@@ -36,6 +36,17 @@ REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken?domain
|
||||
AUTHORIZE_URL = 'https://www.google.com/buzz/api/auth/OAuthAuthorizeToken?domain=anonymous&scope=https://www.googleapis.com/auth/buzz'
|
||||
ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
"""Base error for this module."""
|
||||
pass
|
||||
|
||||
|
||||
class RequestError(Error):
|
||||
"""Request returned failure or unexpected data."""
|
||||
pass
|
||||
|
||||
|
||||
# TODO(ade) This class is really a BuzzGaeBuilder. Rename it.
|
||||
class BuzzGaeClient(object):
|
||||
def __init__(self, consumer_key='anonymous', consumer_secret='anonymous'):
|
||||
@@ -49,7 +60,7 @@ class BuzzGaeClient(object):
|
||||
|
||||
if resp['status'] != '200':
|
||||
logging.warn('Request: %s failed with status: %s. Content was: %s' % (url, resp['status'], content))
|
||||
raise Exception('Invalid response %s.' % resp['status'])
|
||||
raise RequestError('Invalid response %s.' % resp['status'])
|
||||
return resp, content
|
||||
|
||||
def get_request_token(self, callback_url, display_name = None):
|
||||
|
Reference in New Issue
Block a user