Skip to content

Commit

Permalink
Raising an error in case the token is not provided and returning the …
Browse files Browse the repository at this point in the history
…data from the call in get_data method.
  • Loading branch information
koalalorenzo committed Aug 11, 2014
1 parent 89e0f65 commit 86a6415
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion digitalocean/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __perform_request(self, url, type='GET', params=dict()):
using self.__call_api method.
This method will return the request object.
"""
if not self.token:
raise Exception("No token provied. Please use a valid token")

headers = {'Authorization':'Bearer ' + self.token}
if type == 'POST':
r = self.__perform_request(url, headers=headers, params=params)
Expand All @@ -49,7 +52,8 @@ def get_data(self, url, type="GET", params=dict()):
errors too.
"""
req = self.__perform_request(url, type, params)
data = req.json()
if req.status_code != requests.codes.ok:
msg = [data[m] for m in ("id", "message") if m in data][1]
raise Exception(msg)
return req
return data

0 comments on commit 86a6415

Please sign in to comment.