Skip to content

Commit

Permalink
Added error handeling to api.get_token
Browse files Browse the repository at this point in the history
`get_token` would make a request to /ouath2/token and then assume that the
response from that call was valid.  Added a simple check to raise an error
if the request failed.
  • Loading branch information
TheF1rstPancake committed Nov 13, 2015
1 parent 660a5ae commit 4e4ec5c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wepay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,13 @@ def get_token(
if callback_uri:
params.update({'callback_uri': callback_uri})
response = self.call('/oauth2/token', params)

# The call to /oauth2/token should return an access_token
# if the access_token was not returned, then an error occured
# we need to raise this error,
# otherwise this will die when trying to use the 'acess_token' field
if 'access_token' not in response:
raise WePayError(response['error'], response['error_code'], response['error_description'])

self.access_token = response['access_token']
return response

0 comments on commit 4e4ec5c

Please sign in to comment.